elastic search(es) installation

Full-text search is the most common requirement, and the open source  Elasticsearch  (hereinafter referred to as Elastic) is currently the first choice for full-text search engines.

It can quickly store, search and analyze massive data. Wikipedia, Stack Overflow, Github all use it.

 

Underlying Elastic is the open source library  Lucene . However, you can't use Lucene directly, you have to write your own code to call its interface. Elastic is a package of Lucene that provides a REST API operation interface out of the box.

 

1. Installation

Elastic requires a Java 8 environment. If you don't have Java installed on your machine, you can refer to this article , taking care to ensure that the environment variables are JAVA_HOMEset correctly.

java7 should also work.

》》》Install in linux:

$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.1.zip $ unzip elasticsearch-5.5.1.zip $ cd elasticsearch-5.5.1/ 


Next, go to the unzipped directory and run the following command to start Elastic.


$ ./bin/elasticsearch

If you get the error "max virtual memory areas vm.maxmapcount [65530] is too low", run the following command.


$ sudo sysctl -w vm.max_map_count=262144

If all goes well, Elastic will be running on the default port 9200. At this time, open another command line window, request the port, and you will get the description information.


$ curl localhost:9200

{
  "name" : "atntrTf", "cluster_name" : "elasticsearch", "cluster_uuid" : "tf9250XhQ6ee4h7YI11anA", "version" : { "number" : "5.5.1", "build_hash" : "19c13d0", "build_date" : "2017-07-18T20:44:24.823Z", "build_snapshot" : false, "lucene_version" : "6.6.0" }, "tagline" : "You Know, for Search" } 

In the above code, requesting port 9200, Elastic returns a JSON object, including the current node, cluster, version and other information.

Press Ctrl + C and Elastic will stop running.

By default, Elastic only allows local access. If you need remote access, you can modify the config/elasticsearch.ymlfile in the Elastic installation directory, remove network.hostthe comment, change its value 0.0.0.0, and restart Elastic.


network.host: 0.0.0.0 

In the above code, it is set so 0.0.0.0that anyone can access it. Online services should not be set like this, but should be set to a specific IP.



》》》》Install in Windows:
Modify the configuration file

 

 

Then go to the bin and execute elasticsearch.bat (both elasticsearch1 and elasticsearch2 are executed) 
after startup:

 

 

2. Basic Concepts

2.1 Node given Cluster

Elastic is essentially a distributed database that allows multiple servers to work together, each of which can run multiple Elastic instances.

A single Elastic instance is called a node. A group of nodes form a cluster.

2.2 Index

Elastic indexes all fields and writes them into an Inverted Index after processing. When looking up data, look up the index directly.

Therefore, the top-level unit of Elastic data management is called Index. It is synonymous with a single database. The name of each Index (ie database) must be lowercase.

The following command can view all indexes of the current node.


$ curl -X GET 'http://localhost:9200/_cat/indices?v'

2.3 Document

A single record in the Index is called a Document. Many Documents form an Index.

Document is represented in JSON format, the following is an example.


{
  "user": "张三", "title": "工程师", "desc": "数据库管理" } 

Documents in the same Index are not required to have the same structure (scheme), but it is better to keep them the same, which is beneficial to improve search efficiency.

2.4 Type

Documents can be grouped, for example, in weatherthis Index, they can be grouped by city (Beijing and Shanghai), or by climate (sunny and rainy). This grouping is called Type, which is a virtual logical grouping used to filter Documents.

Different Types should have similar schemas, for example, idfields cannot be strings in one group and numbers in another. This is a difference from relational database tables . Data with completely different properties (such as productssum logs) should be stored as two Indexes, rather than two Types in one Index (although it can be done).

The following command can list the Types contained in each Index.


$ curl 'localhost:9200/_mapping?pretty=true'

According to the plan , Elastic 6.x version only allows each Index to contain one Type, and 7.x version will completely remove Type.

3. Create and delete Index

To create a new Index, you can directly send a PUT request to the Elastic server. The following example is to create a new named weatherIndex.


$ curl -X PUT 'localhost:9200/weather'

The server returns a JSON object with acknowledgedfields indicating that the operation was successful.


{
  "acknowledged":true, "shards_acknowledged":true } 

Then, we issue a DELETE request to delete the Index.


$ curl -X DELETE 'localhost:9200/weather'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325825453&siteId=291194637
Recommended