部分我的映射的一对属性的查询是:Elasticsearch。对于在嵌套对象
"individual_attributes" : {
"type" : "nested",
"properties" : {
"template_id" : {"type" : "integer"},
"attributes_set" : {
"type" : "nested",
"properties" : {
"attribute_id" : {"type" : "integer"},
"attribute_value" : {"type" : "string", "index" : "not_analyzed"}
}
}
}
}
我需要筛选那些已与ATTRIBUTE_VALUE attribute_id =“X”为给定的ID等于“Y”的文件。所以我需要匹配一对字段。可能吗?或者,我需要改变我的映射是这样的:
"individual_attributes" : {
"type" : "nested",
"properties" : {
"template_id" : {"type" : "integer"},
"attributes_set" : {
"type" : "nested",
"properties" : {
"attribute_id" : {"type" : "integer",
"properties" : {
"attribute_value" : {"type" : "string", "index" : "not_analyzed"}
}
},
}
}
}
}
的样本数据:
"attributes_set": [
{
"attribute_id": 17,
"attribute_value": "dolorum"
},
{
"attribute_id": 15,
"attribute_value": "at"
},
{
"attribute_id": 18,
"attribute_value": "maxime"
},
{
"attribute_id": 14,
"attribute_value": "et"
},
{
"attribute_id": 11,
"attribute_value": "nemo"
},
{
"attribute_id": 12,
"attribute_value": "rem"
},
{
"attribute_id": 10,
"attribute_value": "eius"
},
{
"attribute_id": 19,
"attribute_value": "deleniti"
},
{
"attribute_id": 13,
"attribute_value": "modi"
},
{
"attribute_id": 16,
"attribute_value": "neque"
}
]
我需要:SELECT * WHERE属性(16,例如)=值(预期值,也)。换句话说,我们需要一个数据集内对匹配字段的:
{
"attribute_id": x,
"attribute_value": "y"
}
非常感谢您的时间和耐心,而您一直在写答案。非常直,细节。这正是我需要的。我更改了使用更多嵌套层次的代码。有,我不知道http://sense.qbox.io。有用的工具。谢谢你指出。现在是将聚合添加到我的过滤器的时候了。 ) –
以及如何添加更多属性集?试过这样,但它没有工作: '“bool”:[“必须”:[{“term”:{...}},...]}, {“must”:[ {“term”:{...}},...]} ] ' –
您必须将整个'nested'子句放在一个'bool-must'中,再加上另一个与您要查找的第二个嵌套文档匹配的嵌套子句。请记住,嵌套过滤器说,“找到符合这些标准的嵌套文档”。如果您正在查找多个嵌套文档,则需要多个嵌套过滤器。 –