如何在两个嵌套对象上创建ElasticSearch过滤器,以便结果仅包含同时符合两个条件的文档

如何在嵌套对象上创建ElasticSearch过滤器查询,以使结果与两者匹配?

我有包含嵌套对象的文档,如下所示:

    {
        "objectNumber": "1","nestedObjects": [
            {
                "category": "position","tag": "2300"
            },{
                "category": "scope","tag": "External"
            }  

            ]
    }

{

    "objectNumber": "2","nestedObjects": [
        {
            "category": "position","tag": "2300"
        },{
            "category": "scope","tag": "Internal"
        }  

        ]
}

{

    "objectNumber": "3","tag": "Internal"
        }  

        ]
}

我想执行一个查询,该查询仅返回包含带有category=positiontag=2300的嵌套对象以及带有category=scopetag=Internal的嵌套对象的文档。 objectNumber 2和3,但不是1。

我已经了解到了:

{
  "query": {
    "nested": {
      "path": "tags","query": {
        "bool": {
          "should": [
            {
              "bool": {
                "filter": [
                  {
                    "match": {
                      "tags.category": "position"
                    }
                  },{
                    "match": {
                      "tags.tag": "2200"
                    }
                  },{
                    "match": {
                      "tags.category": "scope"
                    }
                  },{
                    "match": {
                      "tags.tag": "Internal"
                    }
                  }
                ]
              }
            }

          ]
        }
      }
    }
  }
}

将返回所有3个对象,而不仅仅是2和3。任何帮助将不胜感激。

luoyanzheng 回答:如何在两个嵌套对象上创建ElasticSearch过滤器,以便结果仅包含同时符合两个条件的文档

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3159600.html

大家都在问