es的常用語法(2)

1、基于dis_max實現best fields 進行多字段搜索

1、 best fields和most fields策略

best fields:一個field匹配到了更多的查詢關鍵字,則排在前面
most fields: 多個field匹配到了更多的關鍵字,則排在前面
例如 數據
"id":"1"
"title":"hello java"
"content":"hello test"

"id":"2"
"title":"hi python"
"content":"hello world"

如果查詢條件是

GET /forum/article/_search
{
    "query": {
        "bool": {
            "should": [
                { "match": { "title": "hello world" }},
                { "match": { "content":  "hello world" }}
            ]
        }
    }
}

查詢結果是1在前面,以為1中有兩個符合的條件,這樣的策略就是most field。如果要求2排在前面,則需要使用best field策略

2、使用dis_max實現best field策略
GET student/java/_search{
"query":{
  "dis_max":{
    "query":[
              {"match":{"title":"hello world"}},
              {"match":{"content":"hello world'}}
        ]
}}

搜索:remark字段為1且為2的所有結果(默認的operator為or

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容