【问题标题】:Elasticsearch find missing word in phraseElasticsearch 在短语中查找缺失的单词
【发布时间】:2016-06-05 20:21:32
【问题描述】:

如何使用 Elasticsearch 查找短语中缺失的单词?例如,我想查找包含此模式make * great again 的所有文档,我尝试使用通配符查询但它没有返回任何结果:

   {
  "fields": [
    "file_name",
    "mime_type",
    "id",
    "sha1",
    "added_at",
    "content.title",
    "content.keywords",
    "content.author"
  ],
  "highlight": {
    "encoder": "html",
    "fields": {
      "content.content": {
        "number_of_fragments": 5
      }
    },
    "order": "score",
    "tags_schema": "styled"
  },
  "query": {
    "wildcard": {
      "content.content": "make * great again"
    }
  }
}

如果我输入一个单词并使用 match_phrase 查询,我会得到结果,所以我知道我有与模式匹配的数据。

我应该使用哪种类型的查询?还是我需要在字段中添加某种类型的自定义分析器?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    通配符查询对术语进行操作,因此如果您在分析的字段上使用它,它实际上会尝试分别匹配该字段中的每个术语。在您的情况下,您可以创建一个 not_analyzed 子字段(例如 content.content.raw)并对其运行通配符查询。或者,如果您不需要通过其他方式查询,只需将实际字段映射为不分析即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-02
      • 1970-01-01
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      相关资源
      最近更新 更多