您绝对可以根据作者姓名和日期范围获得结果。
通过此查询,您可以获得与查询匹配的文档已引用的文档数以及文档的计数。
简而言之,您可以根据其他文档获得参考文档的数量
例如,假设您索引 3 个文档
{
"title": "title1",
"author": "bob",
"id": "id1",
"references": [
"id1",
"id2",
"id3"
],
"pubDate": "01-01-2018"
},
{
"title": "title2",
"author": "harry",
"id": "id2",
"references": [
"id1",
"id3",
"id7",
"id8"
],
"pubDate": "01-02-2018"
},
{
"title": "title3",
"author": "bob",
"id": "id3",
"references": [
"id1",
"id4",
"id7",
"id9"
],
"pubDate": "01-03-2018"
}
在此之后,您可以触发查询
GET test_stackoverflow_agg/type1/_search
{
"query": {
"query_string": {
"query": "author:bob AND pubDate:[2018-01-02 TO 2018-01-04]"
}
},
"aggs": {
"agg1": {
"terms": {
"field": "references",
"size": 10
}
}
}
}
查询部分会告诉你要过滤哪些文档和
聚合部分会告诉您要在哪个字段上获取参考字段中存在的唯一 ID 的计数
这是结果的样子
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1.0460204,
"hits": [
{
"_index": "test_stackoverflow_agg",
"_type": "type1",
"_id": "id3",
"_score": 1.0460204,
"_source": {
"title": "title3",
"author": "bob",
"id": "id3",
"references": [
"id1",
"id4",
"id7",
"id9"
],
"pubDate": "2018-01-03"
}
},
{
"_index": "test_stackoverflow_agg",
"_type": "type1",
"_id": "id1",
"_score": 1.0460204,
"_source": {
"title": "title1",
"author": "bob",
"id": "id1",
"references": [
"id1",
"id2",
"id3"
],
"pubDate": "2018-01-02"
}
}
]
},
"aggregations": {
"agg1": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "id1",
"doc_count": 2
},
{
"key": "id2",
"doc_count": 1
},
{
"key": "id3",
"doc_count": 1
},
{
"key": "id4",
"doc_count": 1
},
{
"key": "id7",
"doc_count": 1
},
{
"key": "id9",
"doc_count": 1
}
]
}
}
}