Fast / optimising elasticsearch queries

If you are doing a full text search, a filtered query is best if you can use one. The filtered section of this query is always executed first to get a smaller dataset to run the query on. This will speed up compared to if you filtered after you returned the dataset (potentially called a post_filter).

If you use multiple filters, the filter that returns the most amount of documents should be put last in the list as by the time the order get to this, elastic won't have do to as much work as it processes the filters in order.

Use bool filters if you dont do gelocation, script or numerical range see more here: filter bitsets

You may need to use a variaty of and/or/not and bool filters.

Example:

{
  "filtered": {
    "query": {
      "match": { "tweet": "full text search" }
    },
    "filter": {
      "range": { "created": { "gte": "now-1d/d" }}
    }
  }
}
Details
Updated: 10th March 2016

Play Blokr Now FREE!
blokr.io the web game where you can eat other blocks!