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版本。 –