如果只希望使用
titleid == 1AND 记录,则
personid =='a'可以在两个字段上进行过滤。只有布尔查询使用
must,
should和
most_not。使用过滤器,因为它按照定义进行过滤(例如删除),因此
must
"query": { "bool": { "filter": [ { "term": { "titleId": { "value": 1 } } }, { "term": { "personid": { "value": "a" } } } ] }}更新::
现在,您的问题看起来像是要过滤和汇总结果,然后对这些结果进行汇总。有一些指标和存储桶聚合
使用存储桶选择器聚合 (未经测试,但如果不正确,则应该非常接近)
{ "aggs" : { "title_id" : { "filter" : { "terms": { "personid": ["a","b","c"] } }, "aggs" : { "id_count" : { "count" : { "field" : "titleid" } } } }, aggs": { "count_filter": { "bucket_selector": { "buckets_path": { "the_doc_count": "_count" }, "script": "the_doc_count == 3" } } } }}但是,请注意,管道聚合将对其他聚合产生的输出起作用,因此计算初始doc_counts所需完成的工作总量将是相同的。由于需要为每个输入存储桶执行脚本部分,因此对于高基数字段,操作可能会很慢,如成千上万的术语。



