过滤具有重复ID的嵌套数组对象
嵌套的mailOpens对象数组具有不同的成员。
必须解决此查询: 具有3条不同的mailOpens.mailingId记录的用户列表
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
对于具有不同mailingId的所有成员索引,输出应类似于此:
{
"_index": "members",
"_type": "doc",
"_id": "1234567",
"_score": 2,
"_source": {
"mailOpens": [
{
"created": "04/26/2017",
"mailingId": 1
},
{
"created": "04/26/2017",
"mailingId": 1
},
{
"created": "07/14/2017",
"mailingId": 2
},
{
"created": "07/14/2017",
"mailingId": 2
},
{
"created": "07/14/2017",
"mailingId": 3
},
{
"created": "07/14/2017",
"mailingId": 3
},
{
"created": "07/14/2017",
"mailingId": 4
},
{
"created": "07/14/2017",
"mailingId": 4
}
]
}
}
答案 0 :(得分:0)
我相信ElasticSearch不具有此功能。
从预期的响应中,您要尝试的是从特定文档中过滤数组的结果,而不是在整个群集中进行过滤。我认为您在收到Elastic的回复后需要这样做。最好是,您可能应该在索引时间删除此重复项。
最多,您可以尝试的是汇总以获取计数
GET test/doc/_search
{
"query": {
"match_all": {}
},
"aggs": {
"distint_count": {
"cardinality": {
"field": "mailOpens.mailingId"
}
}
}
}
"aggregations": {
"distint_count": {
"value": 4
}
}
}