elasticsearch语法有哪些
本篇内容主要讲解“elasticsearch语法有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“elasticsearch语法有哪些”吧!
创新新互联,凭借10余年的做网站、网站建设经验,本着真心·诚心服务的企业理念服务于成都中小企业设计网站有上千多家案例。做网站建设,选创新互联。
语法
/ / /
命令
查询所有索引 | GET /_cat/indices GET /_cat/indices?v |
创建索引 | PUT /user |
删除索引 | DELETE /user |
添加文档 | |
删除文档 | |
查询文档 | GET /user/_search |
name字段包含“张三”或“李四”的 | GET /user/_search |
匹配所有文档 | GET /user/_search { "query": { "match_all":{} } } |
所有name字段,包含“张三”的 | GET /user/_search { "query": { "match_phrase":{"name": "张三"} } } |
bool查询 所有数据中,name字段同时 包含”张三“、”李四“的 | GET /user/_search { "query": { "bool": { "must": [ {"match": {"name": "张三"}}, {"match": {"name": "李四"}}, ], } } }
|
bool查询 所有数据中,name字段 包含”张三“或”李四“的 | GET /user/_search { "query": { "bool": { "should": [ {"match": {"name": "张三"}}, {"match": {"name": "李四"}}, ], } } }
|
bool查询 所有数据中,name字段同时 不包含”张三“也不包含”李四“的 | GET /user/_search { "query": { "bool": { "must_not": [ {"match": {"name": "张三"}}, {"match": {"name": "李四"}}, ], } } }
|
bool查询 所有数据中,name字段 包含”张三“,但不包含”李四“的 | GET /user/_search { "query": { "bool": { "must": [ {"match": {"name": "张三"}}, ], "must_not": [ {"match": {"name": "李四"}}, ], } } } |
过滤查询 所有数据中,10<=age<=20的 | GET /user/_search { "query": { "bool": { "must": [ {"match_all": {}}, ], "filter": { "range": {"age": {"gte":10, "lte": 20}} } } } } |
聚合查询 根据state分组,倒序,统计state、count(id) 等同于: SELECT state, COUNT(*) FROM bank GROUP BY state ORDER BY COUNT(*) DESC 说明: size=0 是为了不要查询文档,只要聚合结果 | GET /user/_search |
聚合查询 根据state分组,倒序,统计state、 count(id)、avg(balance) 等同于: SELECT state, COUNT(*), avg(balance) FROM bank GROUP BY state ORDER BY COUNT(*) DESC | GET /user/_search { "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state.keyword" }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } } |
聚合查询 根据state分组,balance平均值倒序,统计state、 count(id)、avg(balance) 等同于: SELECT state, COUNT(*), avg(balance) FROM bank GROUP BY state ORDER BY avg(balance) DESC | GET /user/_search { "size": 0, "aggs": { "group_by_state": { "terms": { "field": "state.keyword", "order": { "average_balance": "desc" } }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } } |
聚合查询 根据age年龄段分组,然后按照性别分组, 然后获取balance平均值 | GET /user/_search { "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.keyword" }, "aggs": { "average_balance": { "avg": { "field": "balance" } } } } } } } } |
到此,相信大家对“elasticsearch语法有哪些”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
网站名称:elasticsearch语法有哪些
文章链接:http://azwzsj.com/article/jgideh.html