Since this is a popular question, I would like to add that in Elasticsearch version 2 things changed a bit.
Instead of filtered
query, one should use bool
query in the top level.
If you don't care about the score of must
parts, then put those parts into filter
key. No scoring means faster search. Also, Elasticsearch will automatically figure out, whether to cache them, etc. must_not
is equally valid for caching.
Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
Also, mind that "gte": "now"
cannot be cached, because of millisecond granularity. Use two ranges in a must
clause: one with now/1h
and another with now
so that the first can be cached for a while and the second for precise filtering accelerated on a smaller result set.