我需要弹性搜索查询的不同记录,就像我们在数据库中那样
select distinct(title) from tablename
而不是
select count(distinct(title)) from tablename
我使用了聚合,但它没有解决我的问题,因为它只提供计数,我需要一些搜索过滤器或任何其他给我这样的结果, 如果我有3条记录:
id title
1 ab is
2 sdf sdf
3 ab is
然后我从查询中获取它,它输出为:
hits : [
1 : ab is
2 : sdf sdf
]
我申请的查询是
{ "query": {
"match" : {"title" : "sing alongs"}
},
"from": 0,
"aggs": {
"genres": {
"terms": {
"field": "title"
}
}
},
"size": 30,
"_source": [
"title"
]}
我得到的结果是
{
{
"_index": "events",
"_type": "Activity",
"_id": "F-m5MGABRY8M87iCVeBZ",
"_score": 21.652287,
"_source": {
"title": "Sing Alongs"
}
} ,
{
"_index": "events",
"_type": "Activity",
"_id": "6OuBwmABRY8M87iCPxNh",
"_score": 9.333357,
"_source": {
"title": "Sing Along"
}
},
{
"_index": "events",
"_type": "Activity",
"_id": "Q-mEIWABRY8M87iC7Ytl",
"_score": 9.320941,
"_source": {
"title": "Sing-Through"
}
}
}
带标题的记录
沿着唱歌
应该只出现一次
答案 0 :(得分:0)
使用size = 1。我无法识别您的查询语言或您使用的环境,但这里是在查询中使用“大小”的文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html