搜索结果正在快递途中

Elasticsearch 聚合的时候要统计一个字段但是条件是这样的

Elasticsearch | 作者 chaochao6411 | 发布于2019年03月29日 | 阅读数:1370

Elasticsearch 聚合的时候要统计一个字段但是条件是这样的:
 
sum( case when custom_float is null then 0 else 1 end )
 
请问应该怎么写?
已邀请:

bellengao - 博客: https://www.jianshu.com/u/e0088e3e2127

赞同来自:

这个查询用exists query就可以实现,一定要聚合吗

God_lockin

赞同来自:

用terms的missing value不可以么?
{
"aggs": {
"agg": {
"terms": {
"field": "field1",
"missing": 0
}
}
}
}

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自:

#试试这个思路


POST /sales/_search?size=0
{
"query" : {
"constant_score" : {
"filter" : {
"match" : { "type" : "hat" }
}
}
},
"aggs" : {
"hat_prices" : {
"sum" : {
"field" : "price",
"missing": 0
}
}
}
}
   

要回复问题请先登录注册