【问题标题】:Query of distinct in elastic search弹性搜索中不同的查询
【发布时间】:2015-08-26 21:38:12
【问题描述】:

SQL 查询:SELECT DISTINCT column FROM table_name WHERE [condition]

我们想在弹性搜索中应用相同的查询,我可以在搜索结果中找到不同的列值。

例如我们有用户索引(userindex)字段是索引用户的学校名称或公司名称的信息。 让有相同学校名称的用户。我想要索引中所有不同的学校名称

【问题讨论】:

标签: java elasticsearch distinct


【解决方案1】:

正如 keety 在 cmets 中所说,一种可能性是使用如下的术语聚合:

curl localhost:9200/users/_search?pretty=1 -d 
{
    "aggs": {
        "schools": {
            "terms": {
                "field": "schoolname"
            }
        }
    }
}

根据您的用例,这可能已经足够了。但是您应该记住,ES 返回的聚合桶有些有限,并且在分页和计数方面可能不准确。

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html

【讨论】:

    猜你喜欢
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-22
    相关资源
    最近更新 更多