3
我想將以下sql查詢轉換爲Elasticsearch。任何人都可以幫忙。將SQL查詢轉換爲ElasticSearch查詢
select csgg, sum(amount) from table1
where type in ('a','b','c') and year=2016 and fc="33" group by csgg having sum(amount)=0
我嘗試以下方法:enter code here
{
"size": 500,
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{"term" : {"fc" : "33"}},
{"term" : {"year" : 2016}}
],
"should" : [
{"terms" : {"type" : ["a","b","c"] }}
]
}
}
}
},
"aggs": {
"group_by_csgg": {
"terms": {
"field": "csgg"
},
"aggs": {
"sum_amount": {
"sum": {
"field": "amount"
}
}
}
}
}
}
,但不知道我在做正確的爲沒有驗證的結果。 似乎查詢被添加到聚合內。
需要採取的行動如下: script.aggs:true script.groovy:true它也像下面這樣說:解析失敗[在[no_amount_filter]]中找不到聚合器類型[bucket_selector]]]; }] – fasterslow2007
你使用Elasticsearch版本> = 2.0.0嗎?對我來說,這聽起來像你使用的是1.x版本。 –