簡體   English   中英

彈性搜索。 嵌套的嵌套查詢

[英]Elasticsearch. Nested query for nested in 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"
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM