Recent projects to use the rapid full-text search, after the preliminary investigation, finally selected Elasticsearch to build a search server. The previous project did not use this search engine, this is the first time.
Mainly referring to the " How to build search engine with node. js and Elasticsearch " This article study, this article translated very well, the whole process has come down very smooth.
The following record I follow this article of the learning process:
1, Learning Elasticsearch Overview.
Know what Elasticsearch is? What can I do? Can check the Elasticsearch, Lucene and other related introduction, but also can check the data comparison of other search engine sphinx, reds and so on.
2, Learning Elasticsearch terminology.
There are only a few core terms listed in the reference article above, and more terminology can be used to find information on its own.
3, install Elasticsearch and run.
A, download elasticsearch: https://www.elastic.co/downloads/elasticsearch
I downloaded the v5.3.0 version of the ZIP package, downloaded and extracted to the local Mac system under the/usr/local/elasticsearch directory.
This version needs java1.8 above (include) support, this can be viewed in the command line with Java-version, not up to the required to upgrade themselves.
B, start the Elasticsearch, the following similar interface shows that the boot was successful. The default 9200 is the HTTP access port, and 9300 is the port on which each node communicates with each other.
>Cd/usr/local/elasticsearch>bin/ elasticsearch[ .-Geneva-31t16: +: +,477][info][o.e.n.node] [] initializing ... [ .-Geneva-31t16: +: +,571][info][o.e.e.nodeenvironment] [ixzpful] using [1] Data paths, mounts [[/(/DEV/DISK1)]], net usable_space [ $.7GB], net total_space [232.6GB], spins?[Unknown], types [hfs][ .-Geneva-31t16: +: +,571][info][o.e.e.nodeenvironment] [ixzpful] heap size [1.9GB], compressed ordinaryObjectpointers [true][ .-Geneva-31t16: +: +,590][info][o.e.n.node] node name [ixzpful] derived from node ID [IXZPFUL9TUA2_I43LJUQDG]; Set [Node.name] to override[ .-Geneva-31t16: +: +,590][info][o.e.n.node] version[5.3.0], pid[5772], build[3adb13b/ .-Geneva-23t03: to: -.652Z], Os[mac OS x/10.12/X86_64], jvm[oracle Corporation/java HotSpot (TM) --bit Server vm/1.8.0_121/25.121-B13] [ .-Geneva-31t16: +: A,642][info][o.e.p.pluginsservice] [ixzpful] loaded module [aggs-matrix-Stats] [ .-Geneva-31t16: +: A,642][info][o.e.p.pluginsservice] [ixzpful] loaded module [ingest-Common] [ .-Geneva-31t16: +: A,642][info][o.e.p.pluginsservice] [ixzpful] loaded module [lang-expression] [ .-Geneva-31t16: +: A,642][info][o.e.p.pluginsservice] [ixzpful] loaded module [lang-Groovy] [ .-Geneva-31t16: +: A,643][info][o.e.p.pluginsservice] [ixzpful] loaded module [lang-Mustache] [ .-Geneva-31t16: +: A,643][info][o.e.p.pluginsservice] [ixzpful] loaded module [lang-Painless] [ .-Geneva-31t16: +: A,643][info][o.e.p.pluginsservice] [ixzpful] Loaded module [percolator][ .-Geneva-31t16: +: A,643][info][o.e.p.pluginsservice] [ixzpful] Loaded module [reindex][ .-Geneva-31t16: +: A,643][info][o.e.p.pluginsservice] [ixzpful] loaded module [transport-Netty3] [ .-Geneva-31t16: +: A,643][info][o.e.p.pluginsservice] [ixzpful] loaded module [transport-Netty4] [ .-Geneva-31t16: +: A,644][info][o.e.p.pluginsservice] [ixzpful] no plugins loaded[ .-Geneva-31t16: +: +,969][info][o.e.n.node] initialized[ .-Geneva-31t16: +: +,969][info][o.e.n.node] [ixzpful] starting ... [ .-Geneva-31t16: +: -,209][info][o.e.t.transportservice] [ixzpful] publish_address {127.0.0.1:9300}, bound_addresses {[FE80::1]:9300}, {[::1]:9300}, {127.0.0.1:9300}[ .-Geneva-31t16: +: -,392][info][o.e.c.s.clusterservice] [ixzpful] New_master {ixzpful}{ixzpful9tua2_i43ljuqdg}{2fmpvtkeqwkuy9ehev26qg}{127.0.0.1}{127.0.0.1:9300}, Reason:zen-disco-elected-as-master ([0] nodes joined) [ .-Geneva-31t16: +: -,412][info][o.e.h.n.netty4httpservertransport] [ixzpful] publish_address {127.0.0.1:9200}, bound_addresses {[FE80::1]:9200}, {[::1]:9200}, {127.0.0.1:9200}[ .-Geneva-31t16: +: -,415][info][o.e.n.node] [ixzpful] started[ .-Geneva-31t16: +: -,553][info][o.e.g.gatewayservice] [ixzpful] recovered [1] indices into cluster_state[ .-Geneva-31t16: +: -,806][info][o.e.c.r.a.allocationservice] [ixzpful] Cluster health status changed from [RED] to [YELLOW] (reason: [Shards star Ted [[Library][2]] ...]).
C, opening http://localhost:9200/in the browser will display some basic information about the instance you are running.
{ "name":"ixzpful", "cluster_name":"Elasticsearch", "Cluster_uuid":"INOWXI3_QSGFG8XG4YHOAA", "version" : { " Number":"5.3.0", "Build_hash":"3adb13b", "build_date":"2017-03-23t03:31:50.652z", "Build_snapshot":false, "lucene_version":"6.4.1" }, "tagline":"Know, for Search"}4, graphical user interface.
Following the options provided in the article, I installed the extensions for Google Chrome Elasticsearch Toolbox. The interface is as follows.
The first select loads an optional index, and the second select loads an optional type. Because no data has been imported yet, there is no option for the moment.
In fact, another plug-in is also very good, address:https://github.com/mobz/elasticsearch-head Interested students can download down to try.
5, node-based Elasticsearch client.
Elasticsearch provides an official module for node. js, called Elasticsearch. This module can be used to encode and elasticsearch communication.
I directly download the sample code to run. The example requires node version 0.11.0 and above.
>git clone https://github.com/sitepoint-editors/node-elasticsearch-tutorial.git #下载示例 >CD node-elasticsearch-Install #安装依赖
The file interpretation in the example can be seen https://github.com/sitepoint-editors/node-elasticsearch-tutorial up to see.
All we need to know now is:
1, Data.json is the test data file, 1000 data.
2. index.js file is an example of importing data from a Data.json file to Elasticsearch. Run with node index.js.
$ node Index.js + file All items
3. Indices.js is used to check the accuracy of index information.
4. Other Elasticsearch test files are examples of data retrieval. There are various ways to do it, and then you can study slowly.
Let's start with a simple query on the pre-installed Elasticsearch Toolbox and try it out.
Because the data was imported. You can now select the Index library in the tool, type article. Then directly click on the query to see the following results:
The result is query all, we can click Query deitor edit query criteria, such as query the author named Rowe Data, the condition is as follows:
{ "Query": { "Match": { "Authors.firstname":"Rowe" } }, " from":0, "size":Ten}
A record can be found.
About Elasticsearch Data retrieval knowledge next article.
Learn to build search engines with node. JS and Elasticsearch (i)