Elasticsearch is becoming more and more popular in the company. Many of my colleagues have never seen Elasticsearch before, so I recently prepared a share about Elasticsearch in the company. This post is for beginners of Elasticsearch, old drivers can be removed.

Elasticsearch is a distributed search and analysis engine that can be used for full text search, structured search and analysis, and can combine all three. Elasticsearch is based on Lucene and is now one of the most widely used open source search engines, with Wikipedia, Stack Overflow, GitHub and others all building their search engines based on Elasticsearch.

In China, there is another Xunsearch that occupies relatively low resources. It only has the function of search, and the analysis engine needs to be written by itself. In the domestic use of enterprises are more, such as Millet and other mobile official websites are using this, relatively simple to use. Mysql Elasticsearch can be used as a resource resource, if your computer is not 2G, you will be sorry to use it. Elasticsearch is used for Elasticsearch 5. Your JAVA SDK must be JAVA SDK 8

The flow chart

Github elasticSearch -rtf github elasticSearch -head elasticsearch config/elasticsearch.yml http.cers. enabled: true http.cors.allow-origin: "*" http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE http.cors.allow-headers: "Requested-With, content-type, content-length, x-user" # install KibanaCopy the code

Cluster: One or more nodes grouped together

Node: A node is identified by a name in the cluster, default is the name of a random comic character

Sharding: The ability to divide an index into multiple pieces, allowing for horizontal splitting and capacity expansion, with multiple sharding requests, improving performance and throughput

Replicas: The ability to create one or more copies of a shard that can be replaced if one node fails

Inverted index problem to be solved

  1. Case conversion problem, into Python and Python should be the same word
  2. Stem extraction, looking and look should be processed words
  3. Participle, if shielding system should be “shielding”, “system” or for “shielding system”
  4. Inverted index file too large – compressed encoding

Install ElasticSearch – RTF

Git clone see https://github.com/medcl/elasticsearch-rtf https://github.com/medcl/elasticsearch-rtf # operation Elasticsearch does not support root by default.  groupadd elsearch useradd elsearch -g elsearch -p elasticsearch next: su elsearchCopy the code

If you see this picture, it is successful. I have done the direction proxy of Nginx, using the host to access the VIRTUAL machine on the local machine





Paste_Image.png

Install elasticSearch -head

Specific operation see https://github.com/mobz/elasticsearch-head idea is: Node.js 6 is the best version of node.js. Many Linux packages come in version 4, Node 4 has a weak API, and make sure you use CNPM. NPM YARN is stuck where there is also a docker installation, the simplest and most secure attention!! Do not use the first method if you are on Linux! There are dependencies that don't run on Linux, like Fsevents in Laravel's front-end development frameworkCopy the code





Paste_Image.png




Paste_Image.png

Kibana install (ElasticSearch)

Must correspond to elasticSearch version, How to see the version Back to look at the above wget https://artifacts.elastic.co/downloads/kibana/kibana-5.1.2-linux-x86_64.tar.gz tar XVF - decompression CD inside / bin/kibana run If feel slow Can use baidu cloud directly to download links: http://pan.baidu.com/s/1kVxLaMr password: 7 ufu then uploaded decompression with FZ toolsCopy the code





Paste_Image.png

Kibana operation on ElasticSearch

PUT lagou {" Settings ":{"index":{"number_of_shards":5, "Number_of_replicas ":1}}} GET lagou/_settings GET _all/_settings GET. Kibana,lagou/_settings GET _setting PUT lagou/_settings{"number_of_replicas":2} "Title" : "python open distributed crawler", and "salary_min:" 15000, "city" : "Beijing", "company" : {" name ":" baidu ", "company_addr" : "Beijing software park"}, "publish_date":"2017-4-16", "comments":15 } GET lagou/job/1 GET lagou/job/1? _source=title GET lagou/job/1? _source=title,city POST lagou/job/1/_update{"doc":{"comments":20}} # DELETE lagou/job/1 DELETE lagou/job DELETE lagouCopy the code

The batch operation

The GET _mget GET testdb job1 is / _mget {" docs ": [{" _id" : 1}, {2} "_id" :]} GET testdb / _mget {" docs ": {" _id" : [1, 2]}} POST _BULK specifies the bulk dataCopy the code

Mapping (mapping)

Type: static and dynamic mapping string:text,keyword(the string type has been deprecated since ES5)

Numeric types: long, integer, short, byte, double, float date: the date bool: Boolean binary types: binary obiject, nested geo - opingt, geo - shape ip,competionCopy the code

Property Store index Null_Value Analyzer include_IN_all format

search

Ik_max_word #match GET lagou/_search {"query":{"match":{"title":"python"}} #term GET lagou/_search {"query":{"term":{"title":"python"}} #terms GET lagou/_search {"query":{"terms":{ "Title" : "python", "engineer", "system", "django"]}}} # control query returns number GET lagou / _search {" query ": {" match" : {" title ":" python "}, "From" : 0, "size" : # 2}} match_all query GET lagou / _search {" query ": {" match_all" : {}, "from" : 0, "size" : 2}}Copy the code

This concludes the basic tutorial

The best thing to solve is how to synchronize mysql data to ElasticSearch. I didn’t know that until I googled elasticSearch was a database

I haven’t tried more dead simple to use elasticsearch – JDBC www.cnblogs.com/zhongshengz… This is the portal

Then you will see how well your application language supports ElasticSearch. Laravel (PHP) laravel-Search is from Mmanos

composer require mmanos/laravel-search dev-master
Copy the code

Use the portal

http://laravelacademy.org/post/3781.html
Copy the code