curl全解node
** 節點(node) **是一個運行着的Elasticsearch實例。git
** 集羣(cluster) **是一組具備相同cluster.name
的節點集合,他們協同工做,共享數據並提供故障轉移和擴展功能,固然一個節點也能夠組成一個集羣。github
Relational DB -> Databases -> Tables -> Rows -> Columns Elasticsearch -> Indices -> Types -> Documents -> Fields
Elasticsearch集羣能夠包含多個索引(indices)(數據庫),每個索引能夠包含多個類型(types)(表),每個類型包含多個文檔(documents)(行),而後每一個文檔包含多個字段(Fields)(列數據庫
這裏我理解的文檔,就是原來在關係型數據庫的狀況下,一條數據存儲時會被分在不一樣的數據庫裏,查詢時會從不一樣的數據庫聚合數據。而在ES中,一條數據不須要被拆分,直接能夠儲存,相同的數據被存儲到一個文檔下面,能夠方便被檢索、排序、過濾。json
一般對象和文檔在某種程度上是等價的,只是表現的形式不一樣。文檔特指最頂層結構或者**根對象(root object)**序列化成的JSON數據(以惟一ID標識並存儲於Elasticsearch中。安全
一個文檔不只包括數據這個主題,還包括一些 metadata
:app
_index
和_type
組合時,就能夠在Elasticsearch中惟一標識一個文檔。當建立一個文檔,你能夠自定義_id
,也可讓Elasticsearch幫你自動生成以下例子展現了文檔的本質:curl
curl -H "content-Type:application/json" -XPOST 'http://localhost:9200/megacorp/employee/1' -d ' { "first_name" : "es", "last_name" : "Smith", "age" : 21, "about" : "I love you", "interests": [ "music"] } ' curl -H "content-Type:application/json" -XPOST 'http://localhost:9200/megacorp/employee/2' -d ' { "first_name" : "ys", "last_name" : "Smith", "age" : 28, "about" : "I love you", "interests": [ "game"] } ' curl -H "content-Type:application/json" -XPOST 'http://localhost:9200/megacorp/employee/3' -d ' { "first_name" : "pinker", "last_name" : "Smith", "age" : 18, "about" : "I love yuxin", "interests": [ "music" ,"game"] } '
{"megacorp": {"aliases":{}, "mappings":{ "employee":{"properties":{ "about":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}, "age":{"type":"long"}, "first_name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}, "interests":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}, "last_name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}} }}}, "settings":{"index":{"creation_date":"1561710155126", "number_of_shards":"5", "number_of_replicas":"1", "uuid":"IMRKdZ_xRd61FLtRXPVVCg", "version":{"created":"6080199"}, "provided_name":"megacorp"}} } }
curl -X GET "localhost:9200/megacorp/employee/3"
對文檔的索引包括如下:elasticsearch
- 簡單搜索: 至關於數據庫查詢
curl -X GET "localhost:9200/megacorp/employee/_search?q=first_name:pinker" {"took":5,"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":"3","_score":0.2876821,"_source": { "first_name" : "pinker", "last_name" : "Smith", "age" : 18, "about" : "I love yuxin", "interests": [ "music" ,"game"] }
curl -H "Content-Type:application/json" -X GET "localhost:9200/megacorp/employee/_search" -d '{ "query":{ "match":{ "first_name":"pinker" } } } '
過濾查詢已被棄用,並在ES 5.0中刪除。 解決: 使用bool / must / filter查詢ide
curl -H "Content-Type:application/json" -X GET "localhost:9200/megacorp/employee/_search" -d ' { "query" : { "bool" : { "filter" : { "range" : { "age" : { "lt" : 25} } }, "must" : { "match" : { "last_name" : "Smith" } } } } }'
curl -H "Content-Type:application/json" -X GET "localhost:9200/megacorp/employee/_search" -d '{ "query":{ "match":{ "about":"yuxin" } } } '
match
查詢變動爲match_phrase
查詢便可
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.0/elasticsearch-analysis-ik-6.8.0.zip
curl -XPOST 'http://localhost:9200/_shutdown'
curl -H "Content-Type: application/json" -XGET 'http://localhost:9200/_count?pretty' -d ' { "query": { "match_all": {} } }
注意:上述中6.X版本開始須要加入頭信息,不然會報不識別格式的錯誤,這是新版ES的更加安全的考慮所致。
curl -i -XGET 'localhost:9200/'
-i
表示回答的報文須要添加完整的http頭。