php - Elasticsearch。嵌套查询嵌套

标签 php elasticsearch nested

我的映射是(部分):

$index =  [
"mappings" => [
    "goods" => [
        "dynamic_templates"=> [
                        [
                            "iattribute_id"=> [
                                "match_mapping_type"=> "string",
                                "match"=>   "attribute_id",
                                "mapping"=> [
                                    "type"=> "integer"
                                ]
                            ]
                        ],
                        [
                            "iattribute_value"=> [
                                "match_mapping_type"=> "string",
                                "match"=>   "attribute_value",
                                "mapping"=> [
                                    "type"=> "string",
                                    "index" => "not_analyzed"
                                ]
                            ]
                        ]
                    ],
        "properties" => [
            ...
            "individual_attributes" => [
                            "type" => "nested",
                            "properties" => [
                                "template_id" => ["type" => "integer"],
                                "attributes_set" => [
                                    "type" => "nested",
                                    "properties" => [
                                        "attribute_id" => ["type" => "integer"],
                                        "attribute_value" => ["type" => "string", "index" => "not_analyzed"]
                                    ]
                                ]
                            ]
                        ]
            ...
        ]
    ]
]
];

如何查询attribute_idattribute_value?它们嵌套在嵌套内部。我不明白如何指定字段的路径。
我已经编写了查询,但是没有用。
GET /index/type/_search
{
"query" : {
  "nested" : {
    "path" : "individual_attributes.attributes_set",
    "score_mode" : "none",
      "filter": {
        "bool": {
          "must": [
            {
              "term" : {
                "individual_attributes.attributes_set.attribute_id": "20"
              }
            },
            {
              "term" : {
                "individual_attributes.attributes_set.attribute_value": "commodi"
              }
            }
          ]
        }
      }
    }
  }

}

最佳答案

试试这个:

{
  "query": {
    "nested": {
      "path": "individual_attributes",
      "score_mode": "none",
      "filter": {
        "nested": {
          "path": "individual_attributes.attributes_set",
          "query": {
            "bool": {
              "must": [
                {
                  "term": {
                    "individual_attributes.attributes_set.attribute_id": "20"
                  }
                },
                {
                  "term": {
                    "individual_attributes.attributes_set.attribute_value": "commodi"
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}

关于php - Elasticsearch。嵌套查询嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33225294/

相关文章:

php - PHP中int的最大值是多少?

php - 无法在 CodeIgniter 中获取验证码图像

php - 使用 Codeigniter 更新数据库表中的字段

amazon-web-services - 如何在AWS中自动删除超过1个月的 Elasticsearch 记录

Elasticsearch 枚举字段

elasticsearch - 在 Elastic 搜索中推荐的人名分析器/过滤器是什么

ruby-on-rails - rails 上的 ruby : Is it possible to nest partial calls/rendering like so:

php - SQL 选择具有相似标签的帖子

MySQL 可以替代嵌套查询吗?

javascript - 如何获取未知 JSON 层次结构的总深度?