Elasticsearch: request does not support [filter]
May 2015.
Problem
Trying to count all results from an index, with a filter, results in a bunch of error:
# curl -XPOST 'http://127.0.0.1:9200/index_name/_count?pretty' -d '{
> "filter":{
> "and":[
> {
> "term":{
> "boolean_field":1
> }
> }
> ]
> }
> }'
{
"count" : 0,
"_shards" : {
"total" : 5,
"successful" : 0,
"failed" : 5,
"failures" : [ {
"index" : "index_name",
"shard" : 0,
"reason" : "BroadcastShardOperationFailedException[[index_name][0] ]; nested: QueryParsingException[[index_name] request does not support [filter]]; "
}, {
"index" : "index_name",
"shard" : 1,
"reason" : "BroadcastShardOperationFailedException[[index_name][1] ]; nested: QueryParsingException[[index_name] request does not support [filter]]; "
}, {
"index" : "index_name",
"shard" : 2,
"reason" : "BroadcastShardOperationFailedException[[index_name][2] ]; nested: QueryParsingException[[index_name] request does not support [filter]]; "
}, {
"index" : "index_name",
"shard" : 3,
"reason" : "BroadcastShardOperationFailedException[[index_name][3] ]; nested: QueryParsingException[[index_name] request does not support [filter]]; "
}, {
"index" : "index_name",
"shard" : 4,
"reason" : "BroadcastShardOperationFailedException[[index_name][4] ]; nested: QueryParsingException[[index_name] request does not support [filter]]; "
} ]
}
}
It's not possible to use elasticsearch to count results from "filter only" queries.
Solution
Use a filtered query:
# curl -XPOST 'http://127.0.0.1:9200/index_name/_count?pretty' -d '{
> "query": {
> "filtered": {
> "filter":{
> "and":[
> {
> "term":{
> "boolean_field":1
> }
> }
> ]
> }
> }
> }
> }'
{
"count" : 89101,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
}
}