部分我的映射的一對屬性的查詢是: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'中,再加上另一個與您要查找的第二個嵌套文檔匹配的嵌套子句。請記住,嵌套過濾器說,「找到符合這些標準的嵌套文檔」。如果您正在查找多個嵌套文檔,則需要多個嵌套過濾器。 –