想要从弹性搜索中获得点击量部分的不同记录



我想根据;departmentNo"。请检查以下索引数据:(这是伪数据。(

{'departmentNo': 1, 'departmentName': 'Food', 'departmentLoc': "I1", "departmentScore": "5", "employeeid" : 1, "employeeName": "vijay", ...}
{'departmentNo': 1, 'departmentName': 'Food', 'departmentLoc': "I1", "departmentScore": "5", "employeeid" : 2, "employeeName": "rathod", ...}
{'departmentNo': 2, 'departmentName': 'Non-Food', 'departmentLoc': "I2", "departmentScore": "6", "employeeid" : 3, "employeeName": "ajay", ...}
{'departmentNo': 2, 'departmentName': 'Non-Food', 'departmentLoc': "I2", "departmentScore": "6", "employeeid" : 4, "employeeName": "kamal", ...}
{'departmentNo': 1, 'departmentName': 'Food', 'departmentLoc': "I1", "departmentScore": "5", "employeeid" : 5, "employeeName": "rahul", ...}

我想要下面的输出。

{'departmentNo': 1, 'departmentName': 'Food', 'departmentLoc': "I1", "departmentScore": "5", "employeeid" : 1, "employeeName": "vijay", ...}
{'departmentNo': 2, 'departmentName': 'Non-Food', 'departmentLoc': "I2", "departmentScore": "6", "employeeid" : 3, "employeeName": "ajay", ...}

我试图在点击量部分获取数据。但没有找到答案。所以我努力了。用于查询

{
"size": 0,
"aggs": {
"Group_By_Dept": {
"terms": {
"field": "departmentNo"
},
"aggs": {
"group_docs": {
"top_hits": {
"size": 1
}
}
}
}
}
}

我通过上面的查询得到了数据。但我想要所有不同的数据,它们应该支持分页+排序。在弹性6.0中,我们可以使用bucket_sort,但我使用的是5.6.7。所以我不能使用bucket_sort。

那么我可以用其他方式吗。?如果我能在点击量部分获得数据,那就太好了。

(我不想改变我的索引映射。实际上,我在这里添加了伪映射。但用例是一样的。(

您可以通过使用字段折叠来做到这一点:

{
"query": { ... },
"from": 153,
"size": 27,
"collapse": {
"field": "departmentNo"
}
}

这将为该字段中的每个重复值只留下一个文档。您可以控制使用标准排序的文档(即,将返回折叠文档中排序值最高的文档(。

请注意,还有一个称为内部点击的附加功能,您可能希望在将来使用它——请注意,它会增加文档获取次数,并对性能产生负面影响。

相关内容

  • 没有找到相关文章

最新更新