Elasticsearch 嵌套对象

Elasticsearch nested object

这是我的映射模板。

{
"settings" : {
    "number_of_shards" : 1,
    "number_of_replicas" : 1
},
"mappings" : {
    "couchbaseDocument" : {
        "properties" : {
            "doc" : { 
                "properties" : {
                    "exMaterialGroupID" : {
                        "type" : "string"
                    },
                    "materialGroupID" : {
                        "type" : "string"
                    },
                    "materialGroupValue" : {
                        "type" : "string"
                    },
                    "productID" : {
                        "type" : "string"
                    },
                    "productImagePath" : {
                        "type" : "string",
                        "fields" : {
                            "ersoy" : {
                                "type" : "string",
                                "index" : "not_analyzed"
                            }
                        }
                    },
                    "productName" : {
                        "type" : "string",
                        "fields" : {
                            "ersoy" : {
                                "type" : "string",
                                "index" : "not_analyzed"
                            }
                        }
                    },
                    "properties" : { 
                        "type" : "nested",
                        "properties" : { 
                            "id" : {
                                "type" : "long"
                            },
                            "name" : {
                                "type" : "string",
                                "fields" : {
                                    "ersoy" : {
                                        "type" : "string",
                                        "index" : "not_analyzed"
                                    }
                                }
                            },
                            "propertyGroupID" : {
                                "type" : "long"
                            }

                        }
                    },
                    "propertyGroups" : {
                        "properties" : {
                            "id" : {
                                "type" : "long"
                            },
                            "name" : {
                                "type" : "string",
                                "fields" : {
                                    "ersoy" : {
                                        "type" : "string",
                                        "index" : "not_analyzed"
                                    }
                                }
                            }
                        }
                    },
                    "propertyOptions" : {
                        "properties" : {
                            "id" : {
                                "type" : "long"
                            },
                            "name" : {
                                "type" : "string",
                                "fields" : {
                                    "ersoy" : {
                                        "type" : "string",
                                        "index" : "not_analyzed"
                                    }
                                }
                            },
                            "propertyID" : {
                                "type" : "long"
                            }
                        }
                    },
                    "searchKey" : {
                        "type" : "string",
                        "fields" : {
                            "ersoy" : {
                                "type" : "string",
                                "index" : "not_analyzed"
                            }
                        }
                    }
                }
            },
            "meta" : {
                "properties" : {
                    "expiration" : {
                        "type" : "long"
                    },
                    "flags" : {
                        "type" : "long"
                    },
                    "id" : {
                        "type" : "string"
                    },
                    "rev" : {
                        "type" : "string"
                    }
                }
            }
        }
    },
    "couchbaseCheckpoint" : {
        "properties" : {
            "doc" : {
                "properties" : {
                    "uuid" : {
                        "type" : "string"
                    }
                }
            }
        }
    }
  }

}

我的问题是使用此聚合搜索产品时

{
 "aggs" : {
    "product" : {
     "nested" : {
            "path" : "properties"
        },

        "aggs" : {
            "id" : {
                "terms" : {
                    "field" : "doc.properties.name.ersoy"
                }
            }
        }
    }
}

}

我收到这个错误。

 {
   "error": "SearchPhaseExecutionException[Failed to execute phase  
 [query_fetch], all shards failed; shardFailures {[bFRHdmHASWCZPk-tbyg4Zw]  [elastic-products1][0]: AggregationExecutionException[[nested] nested path [properties] not found]}]",
    "status": 500
  }

我哪里错了,我看不到。谁能帮帮我

改为尝试此查询,您需要在嵌套路径中使用 "doc.properties" 而不仅仅是 "properties"

{
 "aggs" : {
    "product" : {
     "nested" : {
            "path" : "doc.properties"       <---- fix this line
        },

        "aggs" : {
            "id" : {
                "terms" : {
                    "field" : "doc.properties.name.ersoy"
                }
            }
        }
    }
}