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