我有一个包含父子关系的弹性搜索实现。 父(产品)类型有两种子类型(productfeatures,supplierpna)。
我的应用程序上有搜索功能,需要根据“产品”类型中的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)。