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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容