当前位置:网站首页>Elasticsearch learning one (basic introduction)

Elasticsearch learning one (basic introduction)

2020-11-08 14:58:00 JMCui

One 、Elasticsearch brief introduction

You can describe Elasticsearch :

  • A distributed real-time document storage , Each field can be indexed and searched
  • A distributed real-time analysis search engine
  • Be able to extend hundreds of service nodes , And support PB Level of structured or unstructured data

Elasticsearch Is a real-time distributed search and analysis engine , Built on a full text search engine library Apache Lucene On the basis of , and Lucene It's the most advanced 、 High performance 、 Full featured search engine library .

however Lucene It's just a library . In order to give full play to its function , You need to use Java And will Lucene Integrate directly into the application . What's worse is , You may need an information retrieval degree to understand how it works . because Lucene Very complicated .

Elasticsearch Is also used Java Compiling , Its internal use Lucene Index and search , But its purpose is to make full-text retrieval simple , By hiding Lucene Complexity , Instead, provide a set of simple and consistent RESTful API.

  • Wikipedia uses Elasticsearch Provide full-text search and highlight keywords , And input real-time search (search-asyou-type) And search for error correction (did-you-mean) Wait for the search suggestion function .
  • The guardian uses Elasticsearch Combine user logs and social network data to provide real-time feedback to their editors , In order to keep abreast of the public's response to the newly published articles .
  • StackOverflow Combine full-text search with geographic location query , as well as more-like-this Function to find related questions and answers .
  • Github Use Elasticsearch retrieval 1300 Billion lines of code .
  • ...

Elasticsearch Not only for large enterprises , It also makes things like DataDog as well as Klout Such startups turn their original ideas into scalable solutions ,Elasticsearch Can run on your laptop , It can also be processed on hundreds of servers PB Level of data .

Two 、Elasticsearch install

3、 ... and 、Elasticsearch Data and Retrieval

Elasticsearch It's document oriented , Use JSON As a serialization format for documents , and Elasticsearch It's not just storing documents , It also indexes the content of each document , Make it searchable 、 Sorting and filtering , And this is also Elasticsearch Reasons for supporting complex Full-text Retrieval .

We can use RESTful API Through the port 9200( Default ) and Elasticsearch communicate , have access to kibana visit Elasticsearch , It can even be used directly curl Order to come and Elasticsearch Interaction .

curl -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' -d '<BODY>'

VERB: proper HTTP Method or predicate : GET、POST、PUT、HEAD perhaps DELETE.
PROTOCOL:http perhaps https.
HOST:Elasticsearch The host name of any node in the cluster , Or use localhost Represents the node on the local machine .
PORT:Elasticsearch HTTP The port number of the service , The default is 9200.
PATH:API The terminal path of ( for example _count The number of documents in the cluster will be returned ).Path It may contain multiple components , for example :_cluster/stats and _nodes/stats/jvm .
QUERY_STRING: Optional , Query string parameters ( for example ?pretty Will format the output JSON Return value , Make it easier to read )
BODY: Optional , One JSON Format of the request body

more DSL Grammar can refer to :https://www.elastic.co/guide/en/elasticsearch/reference/7.9/search-search.html

If you are using Java, In the code, you can use Elasticsearch Two built-in clients :

Node client (Node client)
The node client joins the local cluster as a non data node . let me put it another way , It doesn't hold any data on its own , But it knows which node in the cluster the data is in , And it can forward the request to the right node .

Transport client (Transport client)
Lightweight transport clients can send requests to remote clusters . It doesn't join the cluster itself , But it can forward requests to a node in the cluster .

Two Java Clients are all through 9300 Port and use Elasticsearch Native transport protocol and cluster interaction . Nodes in the cluster pass through ports 9300 Communicate with each other . If this port is not open , Nodes will not be able to form a cluster .

版权声明
本文为[JMCui]所创,转载请带上原文链接,感谢