[英]How to compare two date fields in same document in elasticsearch
[英]Compare two elasticsearch document fields from different indexes partitioned by date
我有白天用以下簡化結構分區的數據(考慮數組中的對象是單獨的文檔)。 實際文件數量將超過1000萬:
/products-2019.01.01
[
{
"id": 1,
"name": "Product1",
"price": 15
},
{
"id": 2,
"name": "Product2",
"price": 10
},
{
"id": 3,
"name": "Product3",
"price": 10
}
]
/products-2019.01.02
[
{
"id": 1,
"name": "Product1",
"price": 10
},
{
"id": 2,
"name": "Product2",
"price": 12
},
{
"id": 3,
"name": "Product3",
"price": 10
}
]
/products-2019.01.03
[
{
"id": 1,
"name": "Product1",
"price": 10
},
{
"id": 2,
"name": "Product2",
"price": 10
},
{
"id": 3,
"name": "Product3",
"price": 13
}
]
我的用例是我需要比較兩個確切日期之間的價格,在這種情況下,它可能是:
顯然,每日數據越多,那里的組合就越多。
如果我必須將2019.01.01與2019.01.03進行比較,則查詢必須返回2,因為產品1和產品3的價格在這些索引之間不同。
我正在尋求幫助來構建這樣的查詢,並對任何其他數據模型建議開放。
我認為你可以在這種情況下通過id和price進行匯總,並添加min_doc_count
來過濾掉兩個索引之間不一樣的地方
GET logs1,logs2/_search
{
"size": 0,
"aggs": {
"by_product": {
"terms": {
"script": {
"inline": "doc.id+'_'+doc.price"
},
"min_doc_count": 2
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.