您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“elasticsearch語法有哪些”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“elasticsearch語法有哪些”吧!
語法
<REST> /<Index>/<Type>/<ID>
命令
查詢所有索引 | GET /_cat/indices GET /_cat/indices?v |
創(chuàng)建索引 | 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查詢 所有數(shù)據(jù)中,name字段同時(shí) 包含”張三“、”李四“的 | GET /user/_search { "query": { "bool": { "must": [ {"match": {"name": "張三"}}, {"match": {"name": "李四"}}, ], } } }
|
bool查詢 所有數(shù)據(jù)中,name字段 包含”張三“或”李四“的 | GET /user/_search { "query": { "bool": { "should": [ {"match": {"name": "張三"}}, {"match": {"name": "李四"}}, ], } } }
|
bool查詢 所有數(shù)據(jù)中,name字段同時(shí) 不包含”張三“也不包含”李四“的 | GET /user/_search { "query": { "bool": { "must_not": [ {"match": {"name": "張三"}}, {"match": {"name": "李四"}}, ], } } }
|
bool查詢 所有數(shù)據(jù)中,name字段 包含”張三“,但不包含”李四“的 | GET /user/_search { "query": { "bool": { "must": [ {"match": {"name": "張三"}}, ], "must_not": [ {"match": {"name": "李四"}}, ], } } } |
過濾查詢 所有數(shù)據(jù)中,10<=age<=20的 | GET /user/_search { "query": { "bool": { "must": [ {"match_all": {}}, ], "filter": { "range": {"age": {"gte":10, "lte": 20}} } } } } |
聚合查詢 根據(jù)state分組,倒序,統(tǒng)計(jì)state、count(id) 等同于: SELECT state, COUNT(*) FROM bank GROUP BY state ORDER BY COUNT(*) DESC 說明: size=0 是為了不要查詢文檔,只要聚合結(jié)果 | GET /user/_search |
聚合查詢 根據(jù)state分組,倒序,統(tǒng)計(jì)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" } } } } } } |
聚合查詢 根據(jù)state分組,balance平均值倒序,統(tǒng)計(jì)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" } } } } } } |
聚合查詢 根據(jù)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" } } } } } } } } |
到此,相信大家對(duì)“elasticsearch語法有哪些”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。