I'm trying to fetch data from an elasticsearch index when the following criteria are met.
- When the stream_id is an empty string (e.g. "")
- When the source_id is a specific string (e.g. "unknown_source")
I can use the two following queries separately:
For checking empty string:
`{
"query": {
"filtered": {
"filter": {
"script": {
"script": "_source.stream_id.length() == 0"
}
}
}
}
}`
For checking source_id
`{
"query": {
"bool" : {
"must" : {
"term" : { "source_id" : "unknown_source" }
}
}
}
}`
But now I see the 'filtered' query is deprecated in ES version 2.0 and I'm using version 2.1. So, how do I AND these two conditions? I've looked into the filtered query page documentation and it says
Use the bool query instead with a must clause for the query and a filter
clause for the filter.
So, then I was trying the following query but it's not working.
` {
"query": {
"bool": {
"must" : {
"term" : { "source_id" : "unknown_source" }
},
"filter": {
"script": {
"script": "_source.stream_id.length() == 0"
}
}
}
}
}`