问题描述
根据上面的查询,您将拥有一个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查询示例吗?