多个“匹配短语”包括:弹性搜索中的查询 [英] Multi-"match-phrase" query in Elastic Search

查看:78
本文介绍了多个“匹配短语”包括:弹性搜索中的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对我来说应该是显而易见的,但事实并非如此。以下两个比赛仅在第二阶段进行比赛(在这种情况下,为开普盆地

this should be obvious to me but is not. The following two-match only the second phase (in this case, Cape Basin)

"query": {
  "match_phrase": {
    "contents": {
      "query": "St Peter Fm",
      "query": "Cape Basin"
    }
  }
}

"query": {
  "match_phrase": {
    "contents": {
      "query": ["St Peter Fm", "Cape Basin"]
    }
  }
}

,但以下错误发出错误提示

while the following croaks with an error

"query": {
  "match_phrase": {
    "contents": {
      "query": "St Peter Fm"
    },
    "contents": {
      "query": "Cape Basin"
    }
  }
}

我想匹配包含与输入的短语完全相同的所有文档。

I want to match all documents that contain either phrases exactly as entered.

推荐答案

您的第一个查询并不是有效的JSON对象,因为您两次使用相同的字段名称。

Your first query is not really a valid JSON object because you use the same field name twice.

您可以ea 布尔必须查询以匹配两个短语:

You can use a bool must query to match both phrases:

PUT phrase/doc/1
{
  "text": "St Peter Fm some other text Cape Basin"
}
GET phrase/_search
{
  "query": {
    "bool": {
      "must": [
         {"match_phrase": {"text":  "St Peter Fm"}},
         {"match_phrase": {"text":  "Cape Basin"}}
      ]
    }
 }
}

这篇关于多个“匹配短语”包括:弹性搜索中的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆