I want to query only latest record for each field(c here) for records matching both criteria( A & B). But query below returns multiple results for each c instead of 1.
Mapping: timestamp -> date
e.g.
"timestamp":"2017-04-16T21:26:16"
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"A": "false"
}
},
{
"match_phrase": {
"B": "B1"
}
}
]
}
},
"aggs": {
"c_agg": {
"terms": {
"field": "c",
"size": 1,
"order": {
"max_timestamp": "desc"
}
},
"aggs": {
"max_timestamp": {
"max": {
"field": "timestamp"
}
}
}
}
}
}
What am I missing here?