In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge points of Centos7 installation ElasticSearch instance analysis, the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
1. Download the elasticsearch 6.4.1 installation package
two。 Decompress the package
[root@localhost elasticsearch] # tar-zxvf elasticsearch-6.4.1.tar.gz
3. Start elasticsearch
[root@localhost bin] #. / elasticsearch
Start in the background
[root@localhost bin] #. / elasticsearch-d
Tips:
[root@localhost bin] #. / elasticsearch [2018-09-19t19:46:09817] [warn] [o.e.b.elasticsearchuncaughtexceptionhandler] [] uncaughtexception in thread [main] org.elasticsearch.bootstrap.startupexception: java.lang.runtimeexception: can not run elasticsearch as root at org.elasticsearch.bootstrap.elasticsearch.init (elasticsearch.java:140) ~ [elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.elasticsearch.execute (elasticsearch.java:127) ~ [elasticsearch -6.4.1.jar:6.4.1] at org.elasticsearch.cli.environmentawarecommand.execute (environmentawarecommand.java:86) ~ [elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.cli.command.mainwithouterrorhandling (command.java:124) ~ [elasticsearch-cli-6.4.1.jar:6.4.1] at org.elasticsearch.cli.command.main (command.java:90) ~ [elasticsearch-cli-6.4.1.jar 6.4.1] at org.elasticsearch.bootstrap.elasticsearch.main (elasticsearch.java:93) ~ [elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.elasticsearch.main (elasticsearch.java:86) ~ [elasticsearch-6.4.1.jar:6.4.1] caused by: java.lang.runtimeexception: can not run elasticsearch as root at org.elasticsearch.bootstrap.bootstrap.initializenatives (bootstrap.java:104) ~ [elasticsearch-6.4.1 .jar: 6.4.1] at org.elasticsearch.bootstrap.bootstrap.setup (bootstrap.java:171) ~ [elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.bootstrap.init (bootstrap.java:326) ~ [elasticsearch-6.4.1.jar:6.4.1] at org.elasticsearch.bootstrap.elasticsearch.init (elasticsearch.java:136) ~ [elasticsearch-6.4.1.jar:6.4.1]
Elasticsearch cannot be started in the root user role, so you need to authorize the installation directory to another user and start it with another user
After starting successfully, verify, open a new terminal, and execute the following command:
[root@localhost ~] # curl 'http://localhost:9200/?pretty'{ "name": "o5bavye", "cluster_name": "elasticsearch", "cluster_uuid": "rw1yjlzksgodxkuvgixmxg", "version": {"number": "6.4.1", "build_flavor": "default", "build_type": "tar", "build_hash": "e36acdb" "build_date": "2018-09-13t22:18:07.696808z", "build_snapshot": false, "lucene_version": "7.4.0", "minimum_wire_compatibility_version": "5.6.0", "minimum_index_compatibility_version": "5.0.0"}, "tagline": "you know, for search"} [root@localhost ~] #
The returned message indicates that the installation is successful!
4. Install kibana
Sense is a kibana application that provides an interactive console that submits requests directly to elasticsearch through your browser. The online version of the book contains a link to view in sense with many code examples. When clicked, it opens the sense console of a code example. You don't have to install sense, but it allows you to test the sample code on your local elasticsearch cluster, making the book more interactive.
Download kibana
Kibana is a web interface for data analysis provided by elasticsearch. It can be used for efficient search, visualization, analysis and other operations on the log.
Download and decompress the kibana
[root@localhost elasticsearch] # tar-zxvf kibana-6.4.1-linux-x86_64.tar.gz
Modify the kibana.yml file in the configuration config directory to configure elasticsearch address and kibana address information
Server.host: "192.168.92.50" # kibana server address elasticsearch.url: "http://192.168.92.50:9200" # es address
Start kibana
[root@localhost bin] #. / kibana
Install kibana Native access: http://localhost:5601/
Select the dev tools menu to realize the visual request.
5. Install logstash
Download logstash
After downloading and decompressing, configure log collection log configuration file logstash.conf under the config directory
# sample logstash configuration for creating a simple# beats-> logstash- > elasticsearch pipeline.input {tcp {mode = > "server" host = > "192.168.92.50" port = > 4560 codec = > json_lines}} output {elasticsearch {hosts = > "192.168.92.50 output 9200" index = > "springboot-logstash-% {+ yyyy.mm.dd}"}}
Start logstatsh after successful configuration
[root@localhost bin] #. / logstash-f.. / config/logstash.conf
Some basics of es:
Index (noun):
As mentioned earlier, an index is similar to a database in a traditional relational database and is a place to store relational documents. The plural of index (index) is indices or indexes.
Index (verb):
Indexing a document is to store a document in an index (noun) so that it can be retrieved and queried. This is very similar to the insert keyword in the sql statement, except that the new document replaces the old document when the document already exists.
Inverted index:
Relational databases increase the speed of data retrieval by adding an index such as a b-tree (b-tree) index to a specified column. Elasticsearch and lucene use a structure called an inverted index to achieve the same goal.
Put / megacorp/employee/1 {"first_name": "john", "last_name": "smith", "age": 25, "about": "i love to go rock climbing", "interests": ["sports", "music"]}
Return the result:
#! Deprecation: the default number of shards will change from [5] to [1] in 7.0.0 If you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template {"_ index": "megacorp", "_ type": "employee", "_ id": "1", "_ version": 1, "result": "created", "_ shards": {"total": 2, "successful": 1, "failed": 0}, "_ seq_no": 0, "_ primary_term": 1}
The path / megacorp/employee/1 contains three parts of information:
Megacorp Index name
Employee type name
1 id of a specific employee
Place the second employee information:
{"_ index": "megacorp", "_ type": "employee", "_ id": "2", "_ version": 1, "result": "created", "_ shards": {"total": 2, "successful": 1, "failed": 0}, "_ seq_no": 0, "_ primary_term": 1}
Return the result:
{"_ index": "megacorp", "_ type": "employee", "_ id": "2", "_ version": 1, "result": "created", "_ shards": {"total": 2, "successful": 1, "failed": 0}, "_ seq_no": 0, "_ primary_term": 1}
Place the third employee information
{"_ index": "megacorp", "_ type": "employee", "_ id": "3", "_ version": 1, "result": "created", "_ shards": {"total": 2, "successful": 1, "failed": 0}, "seq_no": 0, "_ primary_term": 1}
5. Retrieve documents
Retrieve the data of a single employee
Get / megacorp/employee/1
Return the result:
{"_ index": "megacorp", "_ type": "employee", "_ id": "1", "_ version": 1, "found": true, "_ source": {"first_name": "john", "last_name": "smith", "age": 25, "about": "i love to go rock climbing", "interests": ["sports", "music"]}
6. Lightweight search
A get is fairly simple, and you can get the specified document directly. Now try some slightly advanced features, such as a simple search!
The first attempt is almost the simplest search. We use the following request to search for all employees:
Get / megacorp/employee/_search
Return the result:
{"took": 31, "timed_out": false, "_ shards": {"total": 5, "successful": 5, "skipped": 0, "failed": 0}, "hits": {"total": 3, "max_score": 1, "hits": [{"_ index": "megacorp", "_ type": "employee", "_ id": "2", "_ score": 1 "_ source": {"first_name": "jane", "last_name": "smith", "age": 32, "about": "i like to collect rock albums", "interests": ["music"]}}, {"_ index": "megacorp", "_ type": "employee", "_ id": "1" "_ score": 1, "_ source": {"first_name": "john", "last_name": "smith", "age": 25, "about": "i love to go rock climbing", "interests": ["sports", "music"]}}, {"_ index": "megacorp", "_ type": "employee" "_ id": "3", "_ score": 1, "_ source": {"first_name": "douglas", "last_name": "fir", "age": 35, "about": "i like to build cabinets", "interests": ["forestry"]}
The result is obtained by name fuzzy matching.
Get / megacorp/employee/_search?q=last_name:smith
Return the result:
{"took": 414, "timed_out": false, "_ shards": {"total": 5, "successful": 5, "skipped": 0, "failed": 0}, "hits": {"total": 2, "max_score": 0.2876821, "hits": [{"_ index": "megacorp", "_ type": "employee", "_ id": "2" "_ score": 0.2876821, "_ source": {"first_name": "jane", "last_name": "smith", "age": 32, "about": "i like to collect rock albums", "interests": ["music"]}}, {"_ index": "megacorp", "_ type": "employee" "_ id": "1", "_ score": 0.2876821, "_ source": {"first_name": "john", "last_name": "smith", "age": 25, "about": "i love to go rock climbing", "interests": ["sports", "music"]}
7. Search using query expressions
Domain specific language (dsl), which specifies the use of an json request
Get / megacorp/employee/_search {"query": {"match": {"last_name": "smith"}
Return the result:
{"took": 7, "timed_out": false, "_ shards": {"total": 5, "successful": 5, "skipped": 0, "failed": 0}, "hits": {"total": 2, "max_score": 0.2876821, "hits": [{"_ index": "megacorp", "_ type": "employee", "_ id": "2" "_ score": 0.2876821, "_ source": {"first_name": "jane", "last_name": "smith", "age": 32, "about": "i like to collect rock albums", "interests": ["music"]}}, {"_ index": "megacorp", "_ type": "employee" "_ id": "1", "_ score": 0.2876821, "_ source": {"first_name": "john", "last_name": "smith", "age": 25, "about": "i love to go rock climbing", "interests": ["sports", "music"]}
8. A more complex search
Search for employees whose last name is smith, but this time we only need employees older than 30, using the filter filter, which supports efficient execution of a structured query
Get / megacorp/employee/_search {"query": {"bool": {"must": {"match": {"last_name": "smith"}, "filter": {"range": {"age": {"gt": 30}
Where: range filter, which can find documents older than 30, where gt indicates that _ is greater than (_ great than)
Return the result:
{"took": 44, "timed_out": false, "_ shards": {"total": 5, "successful": 5, "skipped": 0, "failed": 0}, "hits": {"total": 1, "max_score": 0.2876821, "hits": [{"_ index": "megacorp", "_ type": "employee", "_ id": "2" "_ score": 0.2876821, "_ source": {"first_name": "jane", "last_name": "smith", "age": 32, "about": "i like to collect rock albums", "interests": ["music"]}
9. Full-text search
Search for all employees who like rock climbing.
Get / megacorp/employee/_search {"query": {"match": {"about": "rock climbing"}
Return the result:
{"took": 17, "timed_out": false, "_ shards": {"total": 5, "successful": 5, "skipped": 0, "failed": 0}, "hits": {"total": 2, "max_score": 0.5753642, "hits": [{"_ index": "megacorp", "_ type": "employee", "_ id": "1" "_ score": 0.5753642, "_ source": {"first_name": "john", "last_name": "smith", "age": 25, "about": "i love to go rock climbing", "interests": ["sports", "music"]}}, {"_ index": "megacorp" "_ type": "employee", "_ id": "2", "_ score": 0.2876821, "_ source": {"first_name": "jane", "last_name": "smith", "age": 32, "about": "i like to collect rock albums", "interests": ["music"]}
10. Full-text search
There is no problem finding individual words in an attribute, but sometimes you want to match a series of words or phrases exactly. For example, we want to execute a query that matches only employee records that contain both "rock" and "climbing" and are next to each other in the form of the phrase "rock climbing".
Get / megacorp/employee/_search {"query": {"match_phrase": {"about": "rock climbing"}
Return the result:
{"took": 142,142, "timed_out": false, "_ shards": {"total": 5, "successful": 5, "skipped": 0, "failed": 0}, "hits": {"total": 1, "max_score": 0.5753642, "hits": [{"_ index": "megacorp", "_ type": "employee", "_ id": "1" "_ score": 0.5753642, "_ source": {"first_name": "john", "last_name": "smith", "age": 25, "about": "i love to go rock climbing", "interests": ["sports", "music"]}}]}}
11. Highlight search
Many applications tend to highlight some pieces of text in each search result to let the user know why the document meets the query criteria. It is also easy to retrieve highlighted clips in elasticsearch.
Added parameter: highlight
Get / megacorp/employee/_search {"query": {"match_phrase": {"about": "rock climbing"}}, "highlight": {"fields": {"about": {}
Return the result:
{"took": 250, "timed_out": false, "_ shards": {"total": 5, "successful": 5, "skipped": 0, "failed": 0}, "hits": {"total": 1, "max_score": 0.5753642, "hits": [{"_ index": "megacorp", "_ type": "employee", "_ id": "1" "_ score": 0.5753642, "_ source": {"first_name": "john", "last_name": "smith", "age": 25, "about": "i love to go rock climbing", "interests": ["sports", "music"]} "highlight": {"about": ["i love to go rock climbing"]}
Where the highlight module is the highlight attribute
twelve。 Analysis.
Elasticsearch has a feature called aggregations, which allows us to generate fine-grained analysis results based on the data. Aggregation is similar to but more powerful than group by in sql.
For example, dig out the most popular hobbies among employees:
Get / megacorp/employee/_search {"aggs": {"all_interests": {"terms": {"field": "interests"}
Return the result:
{... "hits": {...}, "aggregations": {"all_interests": {"buckets": [{"key": "music", "doc_count": 2}, {"key": "forestry", "doc_count": 1}, {"key": "sports" "doc_count": 1}]} above is all the content of the article "Centos7 installation ElasticSearch instance Analysis" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.