elasticsearch 返回不同结果的Elasticsearch
以下是我的问题:elasticsearch 返回不同结果的Elasticsearch,elasticsearch,distinct,elasticsearch,Distinct,以下是我的问题: { "fields": [ "news.authorname.raw", "news.authorid" ], "query": { "filtered": { "filter": { "terms": { "news.authorid": [ 1, 2 ]
{
"fields": [
"news.authorname.raw",
"news.authorid"
],
"query": {
"filtered": {
"filter": {
"terms": {
"news.authorid": [
1,
2
]
}
}
}
}
}
通过这个查询,我得到一个对的列表{authord,authorname}。这个列表有重复的{authord,authorname}值,我只需要得到相同的列表,但不要重复。这似乎没那么难,至少今天早上我是这么想的。我对ES知之甚少,加上缺乏文档,使我不顾一切地想找到一个解决这一琐碎问题的方法
当然,我可以通过代码获取整个列表并删除重复,但如果可能的话,我宁愿不接收不必要的数据,也不希望在以后删除它
谁能帮上忙?我应该使用其他方法吗
提前谢谢 我建议使用:
它通常比字段更容易处理,字段有时看起来确实像笛卡尔积。看看这个,好吧,我明白了,但这是否意味着无法获得使用不同值过滤的结果(“命中”数组)?我的意思是,我需要authorid“选择distinct”,因此“bucket”数组对我来说没有用处(ID数组在前端没有任何提示),而“hits”数组仍然包含重复的值。我开始认为我需要这样做,并通过代码过滤不同的值。现在我会这么做,但如果有人能确认这是否是唯一的方法,或者有一些解决方法,可以直接从ES结果中筛选出不同的结果,我将非常感激。谢谢,顺便说一句!!谢谢nefo_x,我已经试过了,但是我一直收到重复的值。
{
"_source": [ "news.authorname.raw", "news.authorid" ],
"query": {
"filtered": {
"filter": {
"terms": {
"news.authorid": [
1,
2
]
}
}
}
}
}