Applying filter condition

Hi

In the following query "Course" is a Array data type.

{
"query": {
"filtered":
{
"filter":
{
"and":
[
{ "terms": { "CategoryId":["3456", "1053"] } },
{ "terms": { "SubType":["1102" , "2348"]} },
{ "terms": { "Course":["1456" , "1458"]} },
{"geo_bounding_box":
{
"location":
{
"top_right":
{
"lat": 4.482137,
"lon": 51.0355306
},
"bottom_left":
{
"lat": 4.482137,
"lon": 51.0146768
}
}
}
}
]
}
}
},
"sort": { "createdDate": { "order": "desc" }}
}

I want to retrive data which has COURSE as "1456" and "1458" right now it works "OR" but I want to apply "AND". How to do it?

If you want to meet both conditions, you need to use a bool query/filter. Ie. replace:

{ "terms": { "Course":["1456" , "1458"]} },

with

{ "bool": {
  "must": [ 
    { "term": { "Course": "1456" } },
    { "term": { "Course": "1458" } }
  ]
 } }
1 Like

It worked Thank you !!