【发布时间】:2018-01-11 09:38:30
【问题描述】:
我需要弹性搜索查询中的不同记录,就像我们在数据库中所做的那样
select distinct(title) from tablename
而不是
select count(distinct(title)) from tablename
我使用了聚合,但它不能解决我的问题,因为它只给出 count ,我需要一些搜索过滤器或其他任何能给我这样的结果的东西, 如果我有 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"
}
}
}
带标题的记录
一起唱歌
这里应该只出现一次
【问题讨论】:
标签: elasticsearch full-text-search