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头。