乐观的 multiIndex 查询以获取所有索引的最大值中的最小值
Optimistic multiIndex query to get min of maximum of all indexes
我正在学习弹性搜索,需要有关多索引搜索查询的帮助。
所以基本上我有 7 个索引。每个索引都有每个文档的 lastUpdatedDate。现在我想一次查询所有选定的索引并获取最后更新日期的最小值和最大值。
例如
index - “A”最后更新于 12 月 20 日 - 所有 lastUpdatedDate 记录的最大值 - 12 月 20 日
索引 - “B” 最后更新于 12 月 18 日 - 所有 lastUpdatedDate 记录的最大值 - 12 月 18 日
索引 - “C” 最后更新于 12 月 19 日 - 所有 lastUpdatedDate 记录的最大值 - 12 月 19 日
这三个指标的最小值是第18。
我可以独立于我的后端服务对所有索引进行查询,但考虑在 Java 中优化查询以一次索引所有这些索引。
再举一个例子:
Index-A {
Id:1, lastUpdatedDate: 15th Dec;
Id:2, lastUpdatedDate: 16th Dec;
Id:5, lastUpdatedDate: 15th Dec;
Id:6, lastUpdatedDate: 20th Dec;
};
Index-B{
Id:1, lastUpdatedDate: 21st Dec;
Id:2, lastUpdatedDate: 16th Dec;
Id:5, lastUpdatedDate: 15th Dec;
Id:6, lastUpdatedDate: 20th Dec;
};
Index-C{
Id:1, lastUpdatedDate: 22nd Dec;
Id:2, lastUpdatedDate: 16th Dec;
Id:5, lastUpdatedDate: 15th Dec;
Id:6, lastUpdatedDate: 20th Dec;
}
现在索引的最大值为:
Index-A -> 20th Dec
Index-B -> 21st Dec
Index-C -> 22nd Dec
然后最小值是 12 月 20 日
一个非常简单的查询就是这个。检索每个索引的最大更新值,然后检索所有这些桶中具有最小值的桶:
GET _all/_search
{
"size": 0,
"aggs": {
"all_indexes": {
"terms": {
"field": "_index",
"size": 100
},
"aggs": {
"max_updated": {
"max": {
"field": "lastUpdatedDate"
}
}
}
},
"min_updated": {
"min_bucket": {
"buckets_path": "all_indexes>max_updated"
}
}
}
}
我正在学习弹性搜索,需要有关多索引搜索查询的帮助。
所以基本上我有 7 个索引。每个索引都有每个文档的 lastUpdatedDate。现在我想一次查询所有选定的索引并获取最后更新日期的最小值和最大值。
例如
index - “A”最后更新于 12 月 20 日 - 所有 lastUpdatedDate 记录的最大值 - 12 月 20 日 索引 - “B” 最后更新于 12 月 18 日 - 所有 lastUpdatedDate 记录的最大值 - 12 月 18 日 索引 - “C” 最后更新于 12 月 19 日 - 所有 lastUpdatedDate 记录的最大值 - 12 月 19 日
这三个指标的最小值是第18。
我可以独立于我的后端服务对所有索引进行查询,但考虑在 Java 中优化查询以一次索引所有这些索引。
再举一个例子:
Index-A {
Id:1, lastUpdatedDate: 15th Dec;
Id:2, lastUpdatedDate: 16th Dec;
Id:5, lastUpdatedDate: 15th Dec;
Id:6, lastUpdatedDate: 20th Dec;
};
Index-B{
Id:1, lastUpdatedDate: 21st Dec;
Id:2, lastUpdatedDate: 16th Dec;
Id:5, lastUpdatedDate: 15th Dec;
Id:6, lastUpdatedDate: 20th Dec;
};
Index-C{
Id:1, lastUpdatedDate: 22nd Dec;
Id:2, lastUpdatedDate: 16th Dec;
Id:5, lastUpdatedDate: 15th Dec;
Id:6, lastUpdatedDate: 20th Dec;
}
现在索引的最大值为:
Index-A -> 20th Dec
Index-B -> 21st Dec
Index-C -> 22nd Dec
然后最小值是 12 月 20 日
一个非常简单的查询就是这个。检索每个索引的最大更新值,然后检索所有这些桶中具有最小值的桶:
GET _all/_search
{
"size": 0,
"aggs": {
"all_indexes": {
"terms": {
"field": "_index",
"size": 100
},
"aggs": {
"max_updated": {
"max": {
"field": "lastUpdatedDate"
}
}
}
},
"min_updated": {
"min_bucket": {
"buckets_path": "all_indexes>max_updated"
}
}
}
}