elasticsearch - 如何在elasticsearch中设置聚合条件
问题描述
假设我有一个索引
"products": {
"aliases": {},
"mappings": {
"products": {
"properties": {
"id": {
"type": "long"
},
"price": {
"type": "double"
},
"discount": {
"type": "double"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
我需要获得所有折扣在 0-10 范围内,价格范围在 5-20 范围内且总价格应小于 200 的产品。
我知道如何过滤字段
{
"query": {
"bool": {
"must": [
{
"range": {
"price": {
"from": 5,
"to": 200,
"include_lower": true,
"include_upper": true,
"boost": 1.0
}
}
},
{
"range": {
"discount": {
"from": 0,
"to": 10,
"include_lower": true,
"include_upper": true,
"boost": 1.0
}
}
}
]
}
}
}
另外,我知道如何汇总价格
"aggregations": {
"total_price": {
"sum": {
"field": "price"
}
}
}
但是如何设置这个 total_price 的界限呢?
解决方案
推荐阅读
- netsuite - 源状态记录到子列表字段
- gstreamer - 如何确保 GStreamer 在解码 jpeg 之前已抓取帧
- python - 在 python 中使用 PIL 加载图像
- javascript - 正则表达式从字符串返回所有图像标签
- c# - 除了使用 SendKeys.Send 之外,在全局范围内替换文本的更好方法
- google-maps - Google Geocode API:相同的地址,不同的坐标
- r - 如何在保留行名的同时对向量进行子集化?
- ios - SearchBar 未显示在导航栏上
- c++ - 一个易于初始化维护和使用 const char* 的类数组?
- node.js - 无法安装 node_modules npm install 错误