elasticsearch,parent-child,Json,elasticsearch,Parent Child" /> elasticsearch,parent-child,Json,elasticsearch,Parent Child" />

Json 获取并附上所有子文档';单个查询中的父项elasticsearch

Json 获取并附上所有子文档';单个查询中的父项elasticsearch,json,elasticsearch,parent-child,Json,elasticsearch,Parent Child,我有一个具有父子关系的弹性搜索实现。 父(产品)类型有两个子类型(productfeatures、supplierpna) 我的应用程序上有搜索功能,需要根据“products”类型中的productcode字段返回父文档 我需要的是通过一个过滤查询将所有子文档作为子嵌套列表附加到父文档 e、 g.productcode=“123456”将返回10个产品,但有些产品有子对象,有些没有,但我希望获取父文档,而不管子文档是否存在 我尝试了has_child选项,但当没有子对象时,它不会返回父文档 这

我有一个具有父子关系的弹性搜索实现。 父(产品)类型有两个子类型(productfeatures、supplierpna)

我的应用程序上有搜索功能,需要根据“products”类型中的productcode字段返回父文档

我需要的是通过一个过滤查询将所有子文档作为子嵌套列表附加到父文档

e、 g.productcode=“123456”将返回10个产品,但有些产品有子对象,有些没有,但我希望获取父文档,而不管子文档是否存在

我尝试了has_child选项,但当没有子对象时,它不会返回父文档

这是我的地图,这方面的任何帮助都将非常有用

{   "itdealer": {
  "aliases": {},
  "mappings": {
     "products": {
        "properties": {
           "categoryname": {
              "type": "string",
              "index_analyzer": "keylower",
              "search_analyzer": "stem",
              "fields": {
                 "categoryname_ags": {
                    "type": "string",
                    "index": "not_analyzed"
                 }
              }
           },
           "highPic": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "id": {
              "type": "string"
           },
           "longDescription": {
              "type": "string"
           },
           "lowPic": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "manufacturername": {
              "type": "string",
              "index_analyzer": "keylower",
              "search_analyzer": "stem",
              "fields": {
                 "manufacturername_ags": {
                    "type": "string",
                    "index": "not_analyzed"
                 }
              }
           },
           "modelName": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "productManualPdfUrl": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "productPdfUrl": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "productSpecifications": {
              "type": "nested",
              "include_in_parent": true,
              "include_in_root": true,
              "include_in_all": true,
              "properties": {
                 "featureGroupName": {
                    "type": "string",
                    "index": "not_analyzed",
                    "index_analyzer": "keylower",
                    "include_in_all": true
                 },
                 "featureGroupName.featureName": {
                    "type": "string",
                    "index": "not_analyzed",
                    "index_analyzer": "keylower",
                    "include_in_all": true
                 },
                 "featureGroupName.featureValue": {
                    "type": "string",
                    "index": "not_analyzed",
                    "index_analyzer": "keylower",
                    "include_in_all": true
                 },
                 "productcode": {
                    "type": "string",
                    "index": "not_analyzed",
                    "index_analyzer": "special",
                    "include_in_all": true
                 }
              }
           },
           "productcode": {
              "type": "string",
              "index": "not_analyzed",
              "store": true,
              "index_analyzer": "special"
           },
           "searchTerms": {
              "type": "string",
              "index_analyzer": "keylower",
              "search_analyzer": "stem"
           },
           "shortDescription": {
              "type": "string",
              "store": true
           },
           "subCategoryname": {
              "type": "string",
              "index_analyzer": "keylower",
              "search_analyzer": "stem",
              "fields": {
                 "subCategoryname_ags": {
                    "type": "string",
                    "index": "not_analyzed"
                 }
              }
           },
           "thumbPic": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "title": {
              "type": "string",
              "analyzer": "keylower",
              "fields": {
                 "title_ac": {
                    "type": "string",
                    "index_analyzer": "pr_autocomplete",
                    "search_analyzer": "keylower"
                 },
                 "title_stem": {
                    "type": "string",
                    "index_analyzer": "stem",
                    "search_analyzer": "keylower"
                 }
              }
           },
           "warrantyInfo": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           }
        }
     },
     "productfeatures": {
        "_parent": {
           "type": "products"
        },
        "_routing": {
           "required": true
        },
        "properties": {
           "featureGroupName": {
              "type": "string",
              "index": "not_analyzed",
              "index_analyzer": "keylower"
           },
           "featureGroupName.featureName": {
              "type": "string",
              "index": "not_analyzed",
              "index_analyzer": "keylower"
           },
           "featureGroupName.featureValue": {
              "type": "string",
              "index": "not_analyzed",
              "index_analyzer": "keylower"
           },
           "features": {
              "properties": {
                 "featureName": {
                    "type": "string"
                 },
                 "featureValue": {
                    "type": "string"
                 }
              }
           },
           "productcode": {
              "type": "string",
              "index": "not_analyzed",
              "index_analyzer": "special"
           }
        }
     },
     "supplierpna": {
        "_parent": {
           "type": "products"
        },
        "_routing": {
           "required": true
        },
        "properties": {
           "freeStock": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "manufacturer": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "partNumber": {
              "type": "string",
              "index": "not_analyzed",
              "store": true,
              "index_analyzer": "special"
           },
           "productcode": {
              "type": "string",
              "index": "not_analyzed",
              "store": true
           },
           "rRP": {
              "type": "double",
              "store": true
           },
           "supplier": {
              "type": "string",
              "index": "not_analyzed",
              "include_in_all": false
           },
           "supplierId": {
              "type": "double",
              "index": "no"
           },
           "supplierLogo": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "supplierName": {
              "type": "string",
              "index": "not_analyzed",
              "index_analyzer": "keylower"
           },
           "supplierProductDescription": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "supplierURL": {
              "type": "string",
              "index": "no",
              "include_in_all": false
           },
           "updatedDate": {
              "type": "date",
              "index": "no",
              "format": "dateOptionalTime",
              "include_in_all": false
           }
        }
     }
  },
  "settings": {
     "index": {
        "mapping": {
           "allow_type_wrapper": "true"
        },
        "search": {
           "slowlog": {
              "threshold": {
                 "fetch": {
                    "warn": "1s"
                 }
              }
           }
        },
        "number_of_shards": "5",
        "merge": {
           "policy": {
              "merge_factor": "10"
           }
        },
        "creation_date": "1432827491555",
        "analysis": {
           "filter": {
              "special": {
                 "split_on_numerics": "false",
                 "generate_word_parts": "false",
                 "preserve_original": "true",
                 "generate_number_parts": "false",
                 "split_on_case_change": "false",
                 "type_table": [
                    "# => ALPHA",
                    "- => ALPHA",
                    "$ => ALPHA",
                    "% => ALPHA"
                 ],
                 "type": "word_delimiter"
              },
              "stemming": {
                 "type": "stemmer",
                 "language": "light_english"
              },
              "autocomplete": {
                 "min_gram": "1",
                 "type": "edge_ngram",
                 "stopwords": "_english_",
                 "max_gram": "20"
              }
           },
           "analyzer": {
              "special": {
                 "filter": [
                    "lowercase",
                    "special"
                 ],
                 "type": "custom",
                 "tokenizer": "keyword"
              },
              "keylower": {
                 "filter": "lowercase",
                 "tokenizer": "standard"
              },
              "pr_autocomplete": {
                 "type": "custom",
                 "filter": [
                    "lowercase",
                    "autocomplete"
                 ],
                 "tokenizer": "standard"
              },
              "stem": {
                 "filter": [
                    "lowercase",
                    "stemming"
                 ],
                 "type": "custom",
                 "tokenizer": "standard"
              }
           }
        },
        "number_of_replicas": "1",
        "version": {
           "created": "1050299"
        },
        "uuid": "D1spSYWURBWIfXYRcsY6cg"
     }
  },
  "warmers": {}}}
我的当前正常搜索查询数据

{
    "query": {
        "filtered": {
            "query": {
                "multi_match": {
                    "fields": [
                        "searchTerms",
                        "manufacturername^7",
                        "subCategoryname^4",
                        "title_ac^10",
                        "categoryname",
                        "shortDescription",
                        "productcode"
                    ],
                    "query": "hp desktop",
                    "type": "cross_fields",
                    "operator": "or",
                    "tie_breaker": 0.3
                }
            }
        }
    },
    "size": "10",
    "from": "0",
    "aggs": {
        "manufacture": {
            "terms": {
                "field": "manufacturername_ags",
                "size": 0,
                "order": {
                    "_count": "desc"
                }
            }
        },
        "category": {
            "terms": {
                "field": "categoryname_ags",
                "size": 0,
                "order": {
                    "_count": "desc"
                }
            }
        },
        "subcategory": {
            "terms": {
                "field": "subCategoryname_ags",
                "size": 0,
                "order": {
                    "_count": "desc"
                }
            }
        }
    }
}
现在,此查询只返回父文档。我希望修改此查询,以便在每个父文档中同时包含子对象(productfeatures和supplierpna)