Elasticsearch使用AND运算符无法匹配多个字段

卡尔提基扬

我正在尝试使用AND运算符从具有多个字段的elasticsearch中获取文档

对于以下查询,期望得到以下结果

AB-7000-8002-W

但是正在收到此错误消息 Unrecognized token 'get': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@40d2a7e8; line: 1, column: 5]

 get my_index12/_search {
    "query" : {
        "bool": {
            "should": [
                {
                    "match": {
                        "code": {
                         "query": "AB-5000-6002-AK",
                         "operator": "and"
                        }
                    }
                },
                {
                    "match": {
                        "locale": {
                         "query": "en_US",
                         "operator": "and"
                        }
                    }
                }
            ]
        }
    }
 }

请在下面找到我的索引文件

 {
        "_index": "my_index12",
        "_type": "doc",
        "_id": "2",
        "_score": 1,
        "_source": {
          "code": "AB-7000-8002-W",
          "locale": "en_US"
        }
      },
      {
        "_index": "my_index12",
        "_type": "doc",
        "_id": "4",
        "_score": 1,
        "_source": {
          "code": "AB-7000-8002-W",
          "locale": "en_EU"
        }
      },
      {
        "_index": "my_index12",
        "_type": "doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "code": "sG66tsdF",
          "locale": "en_US"
        }
      },
      {
        "_index": "my_index12",
        "_type": "doc",
        "_id": "3",
        "_score": 1,
        "_source": {
          "code": "AB-7000-6002-WK",
          "locale": "en_EU"
        }
里查

只需将行中的花括号移到get my_index12/_search {下一行。它应该工作。

为了获得同时满足两个条件的结果,您必须使用must子句而不是shouldmatch查询中的“ AND”运算符不适用于您要实现的用例。使用以下查询。

{
"query": {
"bool": {
  "must": [
    {
      "match": {
        "code": {
          "query": "TE-7000-8002-W",
          "operator": "and"
        }
      }
    },
    {
      "match": {
        "locale": {
          "query": "en_US",
          "operator": "and"
          }
        }
      }
     ]
    }
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章