I have news articles form multiple sources saved and each source have different category I need to write a query which will reverse time sort the article also i don't need more than 3 articles from a particular source I am using the below query but the results are wrong can any one tell me what am i doing wrong.
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"category": "Digital"
}
},
{
"match_phrase": {
"type": "Local"
}
}
]
}
},
"aggs":{
"dedup" : {
"terms":{
"field": "source"
},
"aggs":{
"dedup_docs":{
"top_hits":{
"sort": [
{
"pub_date": {
"order": "desc"
}
}
],
"size": 2
}
}
}
}
},"sort": [
{
"pub_date": {
"order": "desc"
}
}
]
}