我有以下映射搜索查询检索elasticsearch嵌套文档与_source残疾人
{
"cloth": {
"dynamic" : false,
"_source" : {"enabled" : false },
"properties": {
"name": {
"type": "string",
"index": "analyzed"
},
"variation": {
"type": "nested",
"properties": {
"size": {
"type": "string",
"index": "not_analyzed"
},
"color": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
我不能想出一个方法来检索使用字段查询嵌套对象的字段。
{
"fields" : ["name" , "variation.size", "variation.color"],
"query" : {
"nested" : {
"path" : "variation",
"query" : {
"bool" : {
"must" : [
{ "term" : { "variation.size" : "XXL" } },
{ "term" : { "variation.color" : "red" } }
]
}
}
}
}
}
上述查询返回
"_id" : "1",
"_score" : 1.987628,
"fields" : {
"variation.size" : [ "XXL", "XL" ],
"variation.color" : [ "red", "black" ],
"name" : [ "Test shirt" ]
}
当我试图
"fields" : ["name" , "variation"]
我得到了错误
状态:400
reason:“ElasticsearchIllegalArgumentException [字段[变体]不是叶字段]”
这与预期的相同。
如何获取变化对象?
预期结果。我需要检索整个变量对象,以便保留大小和颜色的关联。像“XXL”一样的“红色”。
"variation" : { "XXL" , "red"}
更新:源是该指数类型禁用。
问题1是针对类型禁用源。问题2与您提供的查询结果是2个变体对象。变化:[2] 0:{color:“red”size:“XXL”} - 1:{color:“black”size:“XL”}但我只在寻找一个与XXL和红色相匹配的变体对象。 – user1760178 2014-10-06 13:33:11
1.你不能用'fields'来做你想做的事。 2.如果其中一个嵌套对象与查询匹配,则不仅可以返回匹配的嵌套文档,还会返回包含所有嵌套文档的根文档。 – 2014-10-06 19:55:27
我现在明白了。但是我的问题在于_source查询没有什么帮助,因为这个类型的Source被禁用了。那么,我应该使用什么查询来获取嵌套对象? – user1760178 2014-10-07 13:01:13