I have a JSON document that has an array as follows:
{
...
...
"diagnosis" : [ {
"Description" : "18 WEEKS GESTATION OF PREGNANCY"
}, {
"Description" : "14 WEEKS GESTATION OF PREGNANCY"
} ]
"order_id" : "72C9A1D7AC90AEDDB4F1FAC557FF6DCDF0F16ED29AFFCBDAC1ADED5B524FA419"
}
Please note above that diagnosis has multiple values and I am running aggregation as follows.
{
"size" : 0,
"query":{
"term":{
"order_id":"72C9A1D7AC90AEDDB4F1FAC557FF6DCDF0F16ED29AFFCBDAC1ADED5B524FA419"
}
},
"aggs":{
"filter_diag":{
"filter":{
"term":{
"diagnosis.Description":"18 WEEKS GESTATION OF PREGNANCY"
}
},
"aggs":{
"group_by_diag":{
"terms":{
"field":"diagnosis.Description"
}
}
}
}
}
}
My intension was to include only "18 WEEKS GESTATION OF PREGNANCY" in my aggregation. However, it gave me the below output.
"aggregations" : {
"filter_diag" : {
"doc_count" : 1,
"group_by_diag" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "14 WEEKS GESTATION OF PREGNANCY",
"doc_count" : 1
}, {
"key" : "18 WEEKS GESTATION OF PREGNANCY",
"doc_count" : 1
} ]
}
}
I just want 18 WEEKS GESTATION OF PREGNANCY value only and don't want other value.
Is there a way to filter out unwanted values at ElasticSearch level?