elasticsearch - ElasticSearch多词查询,匹配多个词比匹配几次但多次匹配更有值(value)

标签 elasticsearch search elasticsearch-query

我在ElasticSearch中编写了一个多词搜索查询,匹配多个词比匹配1多次更有值(value)。

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
      }
    }

当我搜索“有效OR日期”时

例如:

"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"
            }
        }
    ]

要获得有关多匹配查询的详细说明,您可以引用此官方documentation

更新1:

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

要获取query_string的详细说明,您可以引用this

更新2:

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

通过使用以上所有三个搜索查询,您将获得相同的搜索结果,并且_score 没有区别

关于elasticsearch - ElasticSearch多词查询,匹配多个词比匹配几次但多次匹配更有值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62420458/

相关文章:

elasticsearch - 即使在设置request_cache = true之后,我也看不到昂贵的ES查询的性能提升

python - 如何通过Python TypeError更新或插入Elasticsearch?

java - Elasticsearch与JAVA的嵌套聚合

elasticsearch - Logstash:如何使用文件名中的日期/时间作为导入字段

elasticsearch - 获取旧索引的Elasticsearch数据

ios - objective-c -按词搜索

php - WordPress 中的多词搜索不显示搜索结果

elasticsearch - Elasticsearch : Can only use prefix queries on keyword and text fields - not on [isXyz] which is of type [boolean]

c# - 多个通配符目录/文件搜索 C# .net 中的任意目录结构

elasticsearch - 使用 Elasticsearch 来搜索号码