I think you do not need to specify a bool filter . If I understand correctly what you are trying to accomplish, a term filter with and filter should be enough. So something like this:
# Delete index # curl -s -X DELETE 'http://localhost:9200/bool-filter-test' ; echo # Create index # curl -s -XPUT 'http://localhost:9200/bool-filter-test/' -d '{ "mappings": { "document": { "properties": { "color": { "type": "string", "index": "not_analyzed" }, "fruit": { "type": "string", "index": "not_analyzed" } } } } }' ; echo # Index some documents # curl -s -XPUT 'http://localhost:9200/bool-filter-test/document/1?pretty=true' -d '{ "fruit" : "apple", "color" : "red" }' ; echo curl -s -XPUT 'http://localhost:9200/bool-filter-test/document/2?pretty=true' -d '{ "fruit" : "apple", "color" : "yellow" }' ; echo curl -s -XPUT 'http://localhost:9200/bool-filter-test/document/3?pretty=true' -d '{ "fruit" : "apple", "color" : "green" }' ; echo curl -s -XPUT 'http://localhost:9200/bool-filter-test/document/4?pretty=true' -d '{ "fruit" : "banana", "color" : "green" }' ; echo curl -s -XPUT 'http://localhost:9200/bool-filter-test/document/5?pretty=true' -d '{ "fruit" : "banana", "color" : "yellow" }' ; echo curl -s -XPUT 'http://localhost:9200/bool-filter-test/document/6?pretty=true' -d '{ "fruit" : "pear", "color" : "green" }' ; echo curl -s -XPUT 'http://localhost:9200/bool-filter-test/document/7?pretty=true' -d '{ "fruit" : "pear", "color" : "yellow" }' ; echo curl -s -XPUT 'http://localhost:9200/bool-filter-test/document/7?pretty=true' -d '{ "fruit" : "pear", "color" : "red" }' ; echo # Refresh index # curl -s -XPOST 'http://localhost:9200/bool-filter-test/_refresh'; echo # This query should return only red apples and pears # curl -s -X POST 'http://localhost:9200/bool-filter-test/_search?pretty' -d '{ "query" : { "match_all" : { } }, "filter" : { "and" : [ { "terms" : { "fruit" : ["apple", "pear"] } }, { "terms" : { "color" : ["red"] } } ] } }'
You can even specify execution - bool (which according to the documentation) Generates a term filter (which is cached) for each term, and wraps those in a bool filter. The bool filter itself is not cached as it can operate very quickly on the cached term filters. Generates a term filter (which is cached) for each term, and wraps those in a bool filter. The bool filter itself is not cached as it can operate very quickly on the cached term filters.
vhyza source share