elasticsearch - Get all documents from elastic search with a field having same value
问题描述
Say I have documents of type Order and they have a field bulkOrderId. Bulkorderid represents a group or bulk of orders issued at once. They all have the same Id like this :
Order {
bulkOrderId": "bulkOrder:12345678";
}
The id is unique and is generated using UUID.
How do I find groups of orders with the same bulkOrderId from elasticsearch when the bulkOrderId is not known? Is it possible?
解决方案
您可以使用terms
聚合和top_hits
子聚合来实现,如下所示:
{
"query": {
"match_all": {}
},
"aggs": {
"bulks": {
"terms": {
"field": "bulkOrderId",
"size": 10
},
"aggs": {
"orders": {
"top_hits": {
"size": 10
}
}
}
}
}
}
推荐阅读
- python - 使用行和列构建 3x3 矩阵-python
- javascript - tinymce 中缺少与上传相关的浏览选项
- laravel - 如何定义未定义变量:token(查看:C:\xampp\htdocs\blog\resources\views\auth\passwords\email.blade.php)
- header - QWebEngine 标头问题
- android - StaggeredLayoutManager 在 RecyclerView 调整期间干扰单元格的位置
- c# - 如何从列表中获取平均值、中位数和标准差
- react-native - 如何在不使用 expo 的情况下在 App 加载之前预加载资产?
- regex - 如何利用 Bash 中的 PCRE 和命名捕获组,以便将变量导出回父环境?
- c# - 如何在 C# 中模拟 linq 表达式
- java - java - 如何使用java拆分除引号内的字符串