【发布时间】:2015-07-12 10:05:52
【问题描述】:
尝试执行 ES 查询时,我在尝试对数组中的对象进行嵌套过滤时遇到了问题。我们的数据结构已经改变:
"_index": "events_2015-07-08",
"_type": "my_type",
"_source":{
...
...
"custom_data":{
"className:"....."
}
}
到:
"_index": "events_2015-07-08",
"_type": "my_type",
"_source":{
...
...
"custom_data":[ //THIS CHANGED FROM AN OBJECT TO AN ARRAY OF OBJECTS
{
"key":".....",
"val":"....."
},
{
"key":".....",
"val":"....."
}
]
}
此嵌套过滤器适用于具有新数据结构的索引:
{
"nested": {
"path": "custom_data",
"filter": {
"bool": {
"must": [
{
"term":
{
"custom_data.key": "className"
}
},
{
"term": {
"custom_data.val": "SOME_VALUE"
}
}
]
}
},
"_cache": true
}
}
但是,当遍历具有较旧数据结构的索引时,它会失败,因此无法添加该功能。理想情况下,我能够找到这两种数据结构,但此时我会接受“优雅的失败”,即不返回结构旧的结果。
我尝试在“custom_data.key”字段上添加“exists”过滤器,并在“custom_data.className”字段的“not”中添加“exists”,但我不断收到“SearchParseException[[events_2015-07 -01][0]: from[-1],size[-1]: Parse Failure [Failed to parse source"
【问题讨论】:
标签: database elasticsearch nested nosql