Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Centos7 installation ElasticSearch 6.4.1 getting started tutorial details

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Download ElasticSearch 6.4.1 installation package download address:

Https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.tar.gz

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] [] uncaught exception 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.

Https://artifacts.elastic.co/downloads/kibana/kibana-6.4.1-linux-x86_64.tar.gz

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

Https://artifacts.elastic.co/downloads/logstash/logstash-7.0.1.tar.gz

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}]}

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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: 247

*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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report