[英]Checking if field exists under an elasticsearch nested aggregation
尝试执行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”上添加“存在”过滤器,并在字段“ custom_data.className”上的“非”内部添加“存在”,但是我一直在获取“ SearchParseException [[events_2015-07-01] [0]:来自[-1],大小[-1]:解析失败[无法解析源代码“
有一个indices
过滤器 (和查询),您可以根据它针对其运行的索引来执行条件过滤器(和查询)。
{
"query" : {
"filtered" : {
"filter" : {
"indices" : {
"indices" : ["old-index-1", "old-index-2"],
"filter" : {
"term" : {
"className" : "SOME_VALUE"
}
},
"no_match_filter" : {
"nested" : { ... }
}
}
}
}
}
}
使用此功能,您应该能够从旧的映射过渡到新的映射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.