【问题标题】:Elasticsearch 2.2 query to test a number of query strings against the same fieldElasticsearch 2.2 查询针对同一字段测试多个查询字符串
【发布时间】:2016-08-09 08:02:31
【问题描述】:

我想知道 somone 是否尝试或推荐了将单个字段与多个查询字符串匹配的最佳方法。解释这一点的最简单方法是说我想在 mysql 中做与WHERE name = "jeff" OR name = "thomas" OR name = "harry" 等效的操作,但将其转换为 elasticsearch 匹配查询。

我希望结果单独采用每个查询条件,而忽略其他查询返回的内容。

实际上就是这个查询

{
    "query": {
                { "match": { "title": "Brown fox" }}
    }
}

但可以添加额外的匹配查询。我可以运行多个查询,但我认为将它作为一个查询运行会更有效(并且更愿意)。

我试过了:

{
    "query": {
        "bool": {
            "should": [
                { "match": { "title": "Brown fox" }},
                { "match": { "body":  "Brown fox" }}
            ]
        }
    }
}

但评分会受到所有查询匹配的影响。理想情况下,我希望分数仅基于单个查询。

dis_max 查询

https://www.elastic.co/guide/en/elasticsearch/guide/current/_best_fields.html#dis-max-query

似乎最接近我所追求的,但得分似乎仍然受到其他查询的影响。dis_match 的得分似乎与query:{match:{}} 得分完全不同。

在一天结束时,我想编写一个查询,尝试匹配查询字符串,但也尝试字符串的一些变体和缩写替换,例如where name="company ltd" OR name="company limited",其中其他条件无关紧要。

问题摘要

有没有人遇到过更好的查询方法来运行具有多个条件的查询,其中每个条件独立于另一个条件并相应地返回结果和分数?

如果没有其他问题,我可能会使用 dis_match 查询类型。

【问题讨论】:

    标签: php elasticsearch


    【解决方案1】:

    最后,我可以保证在同一请求中进行独立搜索的唯一方法是使用多搜索 API 端点并将响应粘贴到一个结果数组中

    https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html#search-multi-search

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 2022-12-04
      • 2011-12-25
      • 2020-02-26
      • 2022-06-29
      • 2015-04-09
      相关资源
      最近更新 更多