【问题标题】:Elasticsearch: multi_match phrase_prefix query with multiple search termsElasticsearch:具有多个搜索词的 multi_match 短语前缀查询
【发布时间】:2016-02-23 17:34:13
【问题描述】:

我有一个包含类似条目的数据库

title: This is my awesome title
abstract: A more detailed descriptions of what [...]

我想构建一个与上述文档匹配的 Elasticsearch 查询,例如,

awe detai

用词表示:具有多个搜索词的多匹配词组前缀查询。 (这旨在用作“键入时搜索”功能。)

我知道您可以如何组合 multi_match 和短语前缀,但我不清楚如何为多个搜索词执行此操作。

有什么提示吗?

【问题讨论】:

  • 您尝试在filter 中使用terms 吗?根据the doc
  • awe detai 所以你的意思是如果用户输入你想找到一个文件?

标签: elasticsearch


【解决方案1】:

好吧,有几种方法可以做到这一点

POST stack/autocomplete/1
{
  "title": "This is my awesome title",
  "abstract": "A more detailed descriptions of what"
}

然后您可以使用带有星号的查询字符串进行搜索,但这里的问题是您需要将 asterix 附加到查询中

POST stack/autocomplete/_search
{
  "query": {
    "query_string": {
      "fields": [
        "title",
        "abstract"
      ],
      "query": "awe* detai*"
    }
  }
}

如果你想匹配用户查询,那么你可以这样使用

POST stack/autocomplete/_search
{
  "query": {
    "multi_match": {
      "fields": [
        "title",
        "abstract"
      ],
      "query": "awesome tit",
      "type": "phrase_prefix"
    }
  }
}

要考虑的另一个选项是将nGram 与查询字符串一起使用,这样您就无需修改用户查询“awe* detai*”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多