I have data from two sources of document one which have status purchased and another does not have status purchased. In order to identify the status purchased i am using a nested object called purchase which have purchase.location and purchase.purchased_on. Thus I am able to identify the item is purchased in second case.
I am building a filter and want to filter the purchased item which should return me data with documents have status purchased or should have purchase.location as one of the value and purchase.purchased_on should be greater than 1.
Elastic Search query built by me is
{
"query": {
"bool": {
"should": [
{
"terms": {
"status": [
"purchased"
]
}
},
{
"bool": {
"should": [
{
"terms": {
"purchase.location": [
"flipkart",
"amazon",
"bestbuy"
]
}
},
{
"range": {
"purchase.purchased_on": {
"gte": 1
}
}
}
]
}
}
]
}
}
}
It only returns data whose status is purchased and does not return the data of other condition.
use nested query,
and the result is,