美文网首页
es的常用语法(2)

es的常用语法(2)

作者: chanyi | 来源:发表于2021-08-27 17:52 被阅读0次

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

相关文章

网友评论

      本文标题:es的常用语法(2)

      本文链接:https://www.haomeiwen.com/subject/oxfvdltx.html