1. 程式人生 > >elasticsearch常用查詢

elasticsearch常用查詢

read 開頭 tro 字符 什麽 details mis 包含 查詢

query DSL
match 查詢
{ 
    "match": { 
        "tweet": "About Search" 
    } 
}
註:match查詢只能就指定某個確切字段某個確切的值進行搜索,做精確匹配搜索時,
你最好用過濾語句,因為過濾語句可以緩存數據。

match_phrase 查詢
{
    "query": {
        "match_phrase": {
            "title": "quick brown fox"
        }
    }
}
註:與match相比,不會拆分查詢條件
參考:https://blog.csdn.net/liuxiao723846/article/details/78365078?locationNum=2&fps=1
multi_match查詢:對多個field查詢 { "multi_match": { "query": "full text search", "fields": [ "title", "body" ] } } bool 查詢 must: 查詢指定文檔一定要被包含。 filter: 和must類似,但不計分。 must_not: 查詢指定文檔一定不要被包含。 should: 查詢指定文檔,滿足一個條件就返回。 POST _search { "query": { "bool" : { "must" : {
"term" : { "user" : "kimchy" } }, "filter": { "term" : { "tag" : "tech" } }, "must_not" : { "range" : { "age" : { "gte" : 10, "lte" : 20 } } }, "should" : [ { "term" : { "tag" : "wow" } }, { "term" : { "tag" : "elasticsearch" } } ],
"minimum_should_match" : 1, "boost" : 1.0 } } } prefix 查詢:以什麽字符開頭 { "query": { "prefix": { "hostname": "wx" } } } wildcards 查詢:通配符查詢 { "query": { "wildcard": { "postcode": "W?F*HW" } } } 註:?用來匹配任意字符,*用來匹配零個或者多個字符 regexp 查詢:正則表達式查詢 { "query": { "regexp": { "postcode": "W[0-9].+" } } } 註: 1. 字段、詞條 字段"Quick brown fox" 會產生 詞條"quick","brown"和"fox" 2. prefix,wildcard以及regexp查詢基於詞條 --------------------------------------------------------------------- filter DSL term 過濾:精確匹配 { "query": { "term": { "age": 26 } } } terms 過濾:指定多個匹配條件 { "query": { "terms": { "status": [ 304, 302 ] } } } range 過濾 { "range": { "age": { "gte": 20, "lt": 30 } } } 範圍操作符包含: gt :: 大於 gte:: 大於等於 lt :: 小於 lte:: 小於等於 exists/missing 過濾:過濾字段是否存在 { "exists": { "field": "title" } } bool過濾:合並多個過濾條件查詢結果的布爾邏輯 { "bool": { "must": { "term": { "folder": "inbox" }}, "must_not": { "term": { "tag": "spam" }}, "should": [ { "term": { "starred": true }}, { "term": { "unread": true }} ] } } 註: must :: 多個查詢條件的完全匹配,相當於 and。 must_not :: 多個查詢條件的相反匹配,相當於 not。 should :: 至少有一個查詢條件匹配, 相當於 or。

elasticsearch常用查詢