Elasticsearch仅获取distinc值为

时间:2016-02-10 14:49:36

标签: elasticsearch

我想排除具有相同元LIKE的结果:

  

从MyDocument中选择DISCTINCT IDParent

我只能获得带有cardinnality的aggs,但我想将它们排除在外

{
"size" : 0,
"aggs" : {
    "distinct_colors" : {
        "cardinality" : {
          "field" : "color",
          "precision_threshold" : 100 
        }
    }
}
}

我想排除对特定元

具有相同值的结果

如果我有

的两个结果
Name = testname 

我想只得到其中一个

1 个答案:

答案 0 :(得分:1)

您可以使用top hits aggregation

执行此操作
{
    "aggs": {
        "top-tags": {
            "terms": {
                "field": "name",
                "size": 0
            },
            "aggs": {
                "top_tag_hits": {
                    "top_hits": {
                       "size" : 1
                    }
                }
            }
        }
    }
}

这应该使用来自field的值来存储所有结果,并且每个桶返回1个文档。您可以使用sort参数控制哪个文档。