ElasticSearch多词查询,匹配多个词比匹配少但多次更有价值

ElasticSearch multi-word query, matching multiple words is more valuable than matching few but many times

我正在 ElasticSearch 中编写多词搜索查询,匹配多个词比匹配 1 个词更有价值,但很多很多次。

1 个跨几个字段的查询:

{
      "bool" : {
        "must" : [
          {
            "simple_query_string" : {
              "query" : "effective date ",
              "fields" : [
                "field1^1.0",
                "field2^5.0",
                "field3^10.0",
              ],
              "flags" : -1,
              "default_operator" : "or",
              "analyze_wildcard" : false,
              "auto_generate_synonyms_phrase_query" : true,
              "fuzzy_prefix_length" : 0,
              "fuzzy_max_expansions" : 50,
              "fuzzy_transpositions" : true,
              "boost" : 1.0
            }
          }
        ],
        "adjust_pure_negative" : true,
        "boost" : 1.0
      }
    }

当我搜索时"effective OR date"

例如:

"This is an example date for effective calculation of the problems"

得分应该高于:

"date date date is what he said to the children"

我该如何微调 elasticsearch?

谢谢!

因为你没有在问题中提到你索引了多少个字段,所以我只取了一个字段,即 title

索引文档:

{
    "title":"This is an example date for effective calculation of the problems"

}
{
    "title":"date date date is what he said to the children"

}

搜索查询:

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "effective date",
            "operator": "or",
            "fields": [
             "title"                    --> If you have more fields, you can 
                                            add them here
            ]
          }
        }
      ]
    }
  }
}

搜索结果:

"hits": [
        {
            "_index": "my_index",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.85874003,
            "_source": {
                "title": "This is an example date for effective calculation of the problems"
            }
        },
        {
            "_index": "my_index",
            "_type": "_doc",
            "_id": "2",
            "_score": 0.289459,
            "_source": {
                "title": "date date date is what he said to the children"
            }
        }
    ]

关于Multi-Match查询的详细解释,可以参考官方documentation

更新 1:

使用query_string

    {
  "query": {
    "query_string": {
      "default_field": "title",
      "query": "effective OR date"
    }
  }
}

query_string的详细解释可以参考this

更新 2:

使用简单_query_string

{
  "query": {
    "simple_query_string" : {
        "query": "effective date",
        "fields": ["title"],
        "default_operator": "or"
    }
  }
}

使用以上三个搜索查询,得到相同的搜索结果,_score

没有区别