如何解决具有分组依据和位置条件的elasticsearch总和聚合
根据上面的查询,您将拥有一个products
带有product
类型文档的索引,该文档的映射如下所示:
curl -XPUT localhost:9200/products -d '
{
"mappings": {
"product": {
"properties": {
"Color": {
"type": "string"
},
"Name": {
"type": "string"
},
"ListPrice": {
"type": "double"
},
"Standardcost": {
"type": "double"
}
}
}
}
}'
{
"query": {
"filtered": {
"query": {
"query_string": {
"default_field": "Name",
"query": "Mountain*"
}
},
"filter": {
"bool": {
"must_not": [
{
"missing": {
"field": "Color"
}
},
{
"term": {
"ListPrice": 0
}
}
]
}
}
}
},
"aggs": {
"by_color": {
"terms": {
"field": "Color"
},
"aggs": {
"total_price": {
"sum": {
"field": "ListPrice"
}
},
"total_cost": {
"sum": {
"field": "Standardcost"
}
}
}
}
}
}
解决方法
我是ElasticSearch的新手。
当前,我们正在将代码从关系数据库迁移到ElasticSearch。因此,我们正在将查询转换为ElasticSearch查询格式。
我正在寻找与以下查询等效的ElasticSearch-
SELECT Color,SUM(ListPrice),SUM(StandardCost)
FROM Production.Product
WHERE Color IS NOT NULL
AND ListPrice != 0.00
AND Name LIKE 'Mountain%'
GROUP BY Color
有人可以为我提供上面的ElasticSearch查询示例吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。