elasticsearch使用
-
查看集群健康情況
curl 'localhost:9200/_cat/health?v'
-
查看集群所有節(jié)點情況
curl 'localhost:9200/_cat/nodes?v'
-
查看集群中所有索引
curl 'localhost:9200/_cat/indices?v'
-
創(chuàng)建索引
curl -XPUT 'localhost:9200/customer?pretty'
-
檢索查詢文檔
curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '{"name": "John Doe"}'
-
刪除索引
curl -XDELETE 'localhost:9200/customer?pretty'
-
修改文檔內(nèi)容
curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '{"name": "John Doe"}'
-
bluk 批量處理
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d ' {"update":{"_id":"1"}} {"doc": { "name": "John Doe becomes Jane Doe" } } {"delete":{"_id":"2"}} '
-
外部數(shù)據(jù)json文件導(dǎo)入
curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json"
query language
-
查詢所有
{ "query": { "match_all": {} } }
-
分頁
{ "query": { "match_all": {} }, "from": 10, "size": 10 }'
-
排序
{ "query": { "match_all": {} }, "sort": { "balance": { "order": "desc" } } }'
-
字段查詢
{ "query": { "match": { "address": "mill" } } }'
{ "query": { "match_phrase": { "address": "mill lane" } } }
-
boolen查詢
{ "query": { "bool": { "must": [ { "match": { "address": "mill" } }, { "match": { "address": "lane" } } ] } } }
{ "query": { "bool": { "must_not": [ { "match": { "address": "mill" } }, { "match": { "address": "lane" } } ] } } }
{
"query": {
"bool": {
"must": [
{ "match": { "age": "40" } }
],
"must_not": [
{ "match": { "state": "ID" } }
]
}
}
}
-
range query
{ "query": { "bool": { "must": { "match_all": {} }, "filter": { "range": { "balance": { "gte": 20000, "lte": 30000 } } } } } }
-
分組統(tǒng)計查詢
{ "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state" } } } }
-
多字段分組
{ "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state" }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } }
-
分組后求平均
{ "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state", "order": { "average_balance": "desc" } }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } }
-
根據(jù)范圍分組
{ "size": 0, "aggs": { "group_by_age": { "range": { "field": "age", "ranges": [ { "from": 20, "to": 30 }, { "from": 30, "to": 40 }, { "from": 40, "to": 50 } ] }, "aggs": { "group_by_gender": { "terms": { "field": "gender" }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } } } }
-java api 手冊
https://legacy.gitbook.com/book/quanke/elasticsearch-java/details