elasticsearch使用
-
查看集群健康情况
curl 'localhost:9200/_cat/health?v'
-
查看集群所有节点情况
curl 'localhost:9200/_cat/nodes?v'
-
查看集群中所有索引
curl 'localhost:9200/_cat/indices?v'
-
创建索引
curl -XPUT 'localhost:9200/customer?pretty'
-
检索查询文档
curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '{"name": "John Doe"}'
-
删除索引
curl -XDELETE 'localhost:9200/customer?pretty'
-
修改文档内容
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"}} '
-
外部数据json文件导入
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 } } } } } }
-
分组统计查询
{ "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" } } } } } }
-
根据范围分组
{ "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