【问题标题】:Elasticsearch exact match for each word in textElasticsearch 精确匹配文本中的每个单词
【发布时间】:2018-04-05 11:22:33
【问题描述】:

我想按以下顺序搜索文本并相应地给出相关性分数:

  1. 匹配准确的词组
  2. 所有字词(确切字词)都应出现在搜索结果中
  3. 结果中应出现一些或至少一个词

这是我的查询:

{
  "_source": [
    "title"
  ],
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "title": {
              "query": "introduction to java",
              "fuzziness": 0,
              "operator": "and",
              "boost": 1
            }
          }
        },
        {
          "match_phrase": {
            "title": {
              "query": "introduction to java",
              "boost": 5
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  },
  "size": 20
}

但我首先得到的是 Javascript 或 jQuery 而不是 java。 结果:

{
"_score": 594.7316,
"_source": {
"title": "Introduction to jQuery Web Development"
}
}
,
{
"_score": 592.86993,
"_source": {
"title": "Introduction to JavaScript Development"
}
}
,
{
"_score": 592.8397,
"_source": {
"title": "A Comprehensive Introduction to Java Virtual Machine (JVM)"
}
}
,
{
"_score": 591.7474,
"_source": {
"title": "Introduction to Java for Programmers"
}
} 

我应该怎么做才能做到这一点?提前致谢。

【问题讨论】:

  • 您的查询对我来说很好 - 除了使用 "operator": "and" 会破坏您的第三条规则,即包含至少包含其中一个术语的结果(将其更改为“或”或只是删除它)。也许可以尝试使用Explain 选项来查看您的结果是如何评分的。
  • 解释选项很好。我得到了一些东西:“描述”:“重量(标题:”(我在 int intr intro introd introdu introduc introduct introducti introductio Introduction)(t to)(j ja jav java)”在 5759)[PerFieldSimilarity],结果:”它在这里搜索任何一个边缘 ngram。但我这里没有使用任何 ngram 分析器

标签: elasticsearch


【解决方案1】:

好的,这是我的错误。 我使用映射 api 在标题字段上应用了 edge_ngram 分析器,这就是它搜索 j/ja/jav/java 的原因。

我删除了索引并创建了一个没有此映射的新索引,并且它对我来说工作正常。

【讨论】:

    猜你喜欢
    • 2023-03-30
    • 2020-04-21
    • 1970-01-01
    • 2015-04-09
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多