Filter vs Query in Elastic 5
The difference is simple: filters are cached and don't influence the score, therefore faster than queries. Have a look here too. Let's say a query is usually something that the users type and pretty much unpredictable, while filters help users narrowing down the search results , for example using facets.
- Right so, if the user is doing a google type search then I would use a query? If they are selecting possible value from a drop down (eg, invoice count > 50) then this would be a filter?
- Yep, that's exactly right. Any time you need to restrict the entire set of documents by some metric, that's usually a case that a filter is appropriate. So maybe by age, length, size, etc etc
As a general rule, filters should be used instead of queries:
As a general rule, queries should be used instead of filters:
You QUERY to the elastic in FILTERED documents
Filter is like Where in LINQ.