elasticsearch - 在聚合和某些条件后返回产品 ID
问题描述
我有一个带有标识符 ( _id
) 的产品列表。我需要以某种方式返回 _id
满足聚合条件和其他一些条件的所有产品标识符(索引中有很多数据)。
我的查询:
GET dev_products/_search
{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"category_id": {
"value": 2233
}
}
},
{
"nested": {
"path": "properties",
"query": {
"bool": {
"must": [
{
"term": {
"properties.char_id": {
"value": 347
}
}
},
{
"term": {
"properties.char_value_id": {
"value": 3480
}
}
}
]
}
}
}
}
]
}
},
"aggs": {
"properties": {
"nested": {
"path": "properties"
},
"aggs": {
"char_values_string": {
"terms": {
"field": "properties.char_value_string",
"size": 10000
},
"aggs": {
"char_ids": {
"terms": {
"field": "properties.char_id",
"size": 10000
}
}
}
},
"min_max_char_values_numeric": {
"terms": {
"field": "properties.char_id",
"size": 10000
},
"aggs": {
"min_char_value_numeric": {
"min": {
"field": "properties.char_value_numeric"
}
},
"max_char_value_numeric": {
"max": {
"field": "properties.char_value_numeric"
}
}
}
}
}
},
"min_price": {
"min": {
"field": "price"
}
},
"max_price": {
"max": {
"field": "price"
}
}
}
}
解决方案
我找到了我的问题的答案(我product_ids
在查询末尾添加)并且它有效:
GET dev_products/_search
{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"category_id": {
"value": 2233
}
}
},
{
"nested": {
"path": "properties",
"query": {
"bool": {
"must": [
{
"term": {
"properties.char_id": {
"value": 347
}
}
},
{
"term": {
"properties.char_value_id": {
"value": 3480
}
}
}
]
}
}
}
}
]
}
},
"aggs": {
"properties": {
"nested": {
"path": "properties"
},
"aggs": {
"char_values_string": {
"terms": {
"field": "properties.char_value_string",
"size": 10000
},
"aggs": {
"char_ids": {
"terms": {
"field": "properties.char_id",
"size": 10000
}
}
}
},
"min_max_char_values_numeric": {
"terms": {
"field": "properties.char_id",
"size": 10000
},
"aggs": {
"min_char_value_numeric": {
"min": {
"field": "properties.char_value_numeric"
}
},
"max_char_value_numeric": {
"max": {
"field": "properties.char_value_numeric"
}
}
}
}
}
},
"min_price": {
"min": {
"field": "price"
}
},
"max_price": {
"max": {
"field": "price"
}
},
"product_ids": {
"terms": {
"field" : "_id",
"size": 10000
}
}
}
}
推荐阅读
- python - 循环遍历列表并查找数字何时停止以相同的速率增加
- c# - 如何从 asp.net core 5 控制器返回 BSON
- flutter - 传递和检索参数 Flutter - 错误:无法在“ModalRoute”上访问属性“设置”
- xamarin.forms - 如何从基类继承并为 Xamarin Forms 中的 ReactiveUI 视图模型指定派生类?
- microsoft-graph-api - 向群组中的用户发送消息
- flutter - 如何在我的颤振应用程序中显示网页?
- linux - 在 x64 Linux 上,syscall、int 0x80 和 ret 退出程序有什么区别?
- mysql - 我怎样才能对 SQL 数据库进行这个复杂的查询
- google-apps-script - 如何从另一个组 appscript webapp 发送电子邮件
- sql - Redshift - 限制对视图定义中使用的引用对象的访问