[英]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.