Hello,
A minimal data example:
...
References: [
{
DocType: { SysName: "order"}
DocId: "12345"
},
{
"DocType: {SysName: "invoice"}
"DocId: "22222"}
]
MessageDate: "05/05/20"
...
I need to query this data, scan the references and return all the distinct doc Ids of type order while supporting paging and sorting if possible.
I am trying to figure out how to query this.
So far I tried something like this :
{
"aggs":{
"docType":{
"terms":{
"field":"References.DocType.SysName.keyword"
},
"aggs": {
"docId": {
"terms": {
"field": "References.DocId.keyword",
"size": 10000
}
}
}
}
},
"query":{
"bool":{
"filter":[
{
"range":{
"MessageDate":{
"gte":"2015-05-24T00:00:00+03:00"
}
}
}
]
}
}
}
The response is :
"buckets": [
{
"key": "order",
"doc_count": ...,
"docId": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": ...,
"buckets": [
{
"key": "12345",
"doc_count": 1
}]
...
This is sort of gives me what I need but I think I it is the wrong direction.
Because I also need to support paging probably with the - from, size parameters.
So Ideally I would have wanted to somehow return this information in the _source, hits body.