Basically, you should put at the end filters which have the heavier cost. For example a geo filter should be computed at the very end.
Also, non cached filters should be placed at the end. For example, if you have a date range filter using « now » which is not cached. It’s not really related to the number of documents which are matching or not the filter. Though elasticsearch tries to optimize that behind the scene. Note also that cache plays a really important role even if Lucene is really fast. Hope this helps. -- David Pilato | Technical Advocate | elasticsearch.com [email protected] @dadoonet | @elasticsearchfr | @scrutmydocs Le 21 septembre 2014 à 07:39:41, Mouzer ([email protected]) a écrit: For my requirements, I need to have a filter like below: { "filter": { "bool": { "must": [ { "bool": { "should": [ { "term": { "field1": "value1x" } } ] } }, { "bool": { "should": [ { "term": { "field2": "value2x" } } ] } } ] } } This is a simplified example. There can be multiple values for the fields field1 and/or field2 and hence the inner should filter. I know for a fact that the should filter for field2 will usually match much less documents than the should filter for field1. After reading this, it is clear that had I used field1 and field2 directly under the same must filter, I should have specified field2 before field1. Ask: 1. Does the filter ordering theory hold in general for nested filters like in my case? Will I gain in performance if I put the should filter for field2 before the should filter for field1? Let's assume that these filters are not cached. 2. Does the reverse of the filter ordering theory hold for should filters - that filters matching most documents should appear before filters matching less documents in a should filter? 3. Does this same theory hold for and/or filters just like it holds for must/should filters? 4. Just for my information, for this theory to work, the filters must be "evaluated" in a sequence and not in parallel. Correct? -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/84829783-d67c-464a-9f19-f6aa5309136f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/etPan.541ea35e.625558ec.2bf8%40MacBook-Air-de-David.local. For more options, visit https://groups.google.com/d/optout.
