我试图创建一个动态映射像对象的以下:动态映射为嵌套类型
{
"product": {
"productId": 99999,
"manufacturerId": "A0001",
"manufacturerCode": "A101LI",
"name": "Test Product",
"description": "Describe the product here.",
"feature_details":{
"category": "Category1",
"brand": "Brand Name"
},
"feature_tpcerts":{
"certifiedPass": true,
"levelCertified": 2
},
"feature_characteristics":{
"amount": 0.73,
"location": 49464
}
}
}
我想feature_*
属性是一个嵌套类型,这是我在下面的映射定义nested_feature模板和它按预期工作。但是,我还希望将feature_*
属性的嵌套对象中的每个属性都设置为multi_value
并定义了额外的facet
属性。我试过第二个nested_template模板,但没有任何成功。
{
"product" : {
"_timestamp" : {"enabled" : true, "store": "yes" },
"dynamic_templates": [
{
"nested_feature": {
"match" : "feature_*",
"mapping" : {
"type" : "nested",
"stored": "true"
}
}
},
{
"nested_template": {
"match": "feature_*.*",
"mapping": {
"type": "multi_field",
"fields": {
"{name}": {
"type": "{dynamic_type}",
"index": "analyzed"
},
"facet": {
"type": "{dynamic_type}",
"index": "not_analyzed"
}
}
}
}
}
],
"properties" : {
"productId" : { "type" : "integer", "store" : "yes"},
"manufacturerId" : { "type" : "string", "store" : "yes", "index" : "analyzed"},
"manufacturer" : { "type" : "string", "store" : "yes", "index" : "not_analyzed"},
"manufacturerCode" : { "type" : "string", "store" : "yes"},
"name" : {"type" : "string", "store" : "yes"},
"description": {"type": "string", "index" : "analyzed"}
}
}
}
不幸的是,feature_*
属性中的属性是从另一个进程创建,并且可以是几乎任何名称/值对。有关如何使用动态模板设置嵌套属性的任何建议,以及使嵌套对象multi_field
中的每个属性都具有其他facet
属性?
这完美地工作!感谢关于字段类型匹配的建议,存储字段/ _source字段和文档结构。我对使用Elasticsearch很感兴趣,并且非常感谢这些技巧。 –
@PaigeCook欢迎您,非常感谢elasticsearch,我相信您很快就会开始回答有关它的问题! ;) – javanna