您好,登錄后才能下訂單哦!
本篇內容主要講解“elasticsearch語法有哪些”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“elasticsearch語法有哪些”吧!
語法
<REST> /<Index>/<Type>/<ID>
命令
查詢所有索引 | 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語法有哪些”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。