如何进行ElasticSearch选择不同 [英] How to do an ElasticSearch Select Distinct

查看:58
本文介绍了如何进行ElasticSearch选择不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想对Elasticsearch进行以下请求。

I just want to do the following request with elasticsearch.

在SQL中:

Select distinct(id) from my_table where userid = '20' or activity = '9';

我只是有:

{
   "query" : {
        "bool" : {
               "should" : [ 
                  { "term" : { "userid" : "20" } }, 
                  { "term" : { "activity" : "9" } }
               ]
         }
    }
}

谢谢:)

推荐答案

您快到了,您只需要添加 条款聚合到您的查询

You're almost there, you simply need to add a terms aggregation to your query

{
   "query" : {
        "bool" : {
               "should" : [ 
                  { "term" : { "userid" : "20" } }, 
                  { "term" : { "activity" : "9" } }
               ]
         }
    },
    "aggs":{
        "unique_ids": {
            "terms": {
                "field": "id"
            }
        }
    }
}

这篇关于如何进行ElasticSearch选择不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆