2015-10-19 418 views
2

我的映射(的一部分):Elasticsearch。嵌套查詢嵌套在嵌套

$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" 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 

} 

回答

1

試試這個:

{ 
    "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" 
        } 
       } 
       ] 
      } 
      } 
     } 
     } 
    } 
    } 
} 
+0

它不工作...莫比有毛病我映射。 GET/index/_mapping/type爲我提供了以下內容 - laravel.io/bin/8KW8v –

+0

如果這是您的映射,則索引中存在更嚴重的問題。根據您在php中的映射,映射不包含'nested'字段。因此,索引不是創建的,你認爲它是在你的php代碼中,或者該映射屬於不同的索引。 –

+0

我無法查看映射(laravel.io/bin/fork/yGvY6),除非我在github中給予我的私人電子郵件地址的讀取權限。我不打算這樣做。但是,正如我所說的,我在** laravel.io/bin/8KW8v **中看到的映射與您在php代碼中的映射不匹配。沒有什麼可以補充的。您需要修復您的映射,以便這些字段是嵌套的。然後我建議的查詢將起作用。 –