多字段匹配查询 [英] Query with match by multiple fields

查看:15
本文介绍了多字段匹配查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是弹性搜索的新手,想编写一个关注两个字段的查询.我的意思是字段的内容包含指定的子字符串.我有一个包含字段的文档,如下所示:

I'm pretty new to elastic search and would like to write a query that is concerned about two fields. I mean the content of the fields contains the specified substring. I have a document containing fields, like this:

name: n
tag: t

我试过了:

/_search -d '
{
    "query": {
        "match": {
             "name": "n",
             "tag": "t"
        }
    }
}

但是查询导致如下错误:

But the query results in the following error:

[match] 查询以简化形式解析,具有直接字段名称,但包括更多的选项,而不仅仅是字段名称,可能使用它的'options' 表单,带有 'query' 元素?

[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?

有没有办法在弹性搜索中做到这一点?

Is there a way to do this in elasticsearch?

推荐答案

您需要在 bool/must 查询中包含两个 match 查询,如下所示:

You need two match queries enclosed in a bool/must query, like this:

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "n"
          }
        },
        {
          "match": {
            "tag": "t"
          }
        }
      ]
    }
  }
}

这篇关于多字段匹配查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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