根据上面的查询,您将拥有一个
products带有
product类型文档的索引,该文档的映射如下所示:
curl -XPUT localhost:9200/products -d '{ "mappings": { "product": { "properties": { "Color": { "type": "string" }, "Name": { "type": "string" }, "ListPrice": { "type": "double" }, "StandardCost": { "type": "double" } } } }}'然后,相当于您上面给出的SQL的ES查询如下所示:
{ "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" } } } } }}


