Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching for term and range in same bool filter in elasticsearch

My query is like:

query: {
    filtered: {
        filter: {
            bool: {
                must: [
                    range: {price: {gte: 222, lte: 1000}},
                    term: {city: Adana}
                ]
            }
        }
    }
}

It returns empty result. But doing same using uri search (_search?q=city:Adana gives correct result.

Giving multiple range queries, like latitude and price works, but adding term fails.

What can be problem here?

like image 251
Emin Mastizada Avatar asked Sep 15 '15 14:09

Emin Mastizada


1 Answers

Try this:

query: {
    filtered: {
        filter: {
            bool: {
                must: [
                    { range: {price: {gte: 222, lte: 1000}} },
                    { term: {city: Adana} }
                ]
            }
        }
    }
}

Here is some code I used to test it:

http://sense.qbox.io/gist/7a4811d00e562f4d41e252ae5084ec78fa23d80f

like image 54
Sloan Ahrens Avatar answered Nov 18 '22 21:11

Sloan Ahrens