What is the difference between Query and Filter in Elasticsearch? - Big Data In Real World

What is the difference between Query and Filter in Elasticsearch?

How to force Spark to use Shuffle Hash Join when it defaults to Sort Merge Join?
February 19, 2021
What is the difference between hadoop fs put and copyFromLocal?
February 24, 2021
How to force Spark to use Shuffle Hash Join when it defaults to Sort Merge Join?
February 19, 2021
What is the difference between hadoop fs put and copyFromLocal?
February 24, 2021

Elasticsearch offers 2 different contexts on how you have query or filter documents in an index – Query context and Filter context.

Query context

  • In the query context, a query clause answers the question “How well does this document match this query clause?
  • In query context, Elasticsearch tries to determine whether the document matches the search text and how well it matches.
  • Will provide a relevance _score in the output which tells you the relevance of the match result.
  • Results are not cached

Eg. book_description field contains the word amazingly realistic.

Filter context

  • In a filter context, a query clause answers the question “Does this document match this query clause?
  • Filter context evaluates to a simple “Yes” or “No”
  • Doesn’t provide you with relevance _score
  • Frequently used filters will be cached automatically by Elasticsearch, to speed up performance.

Eg. book_status field is published

Example

curl -X GET "localhost:9200/book/_search?pretty" -H 'Content-Type: application/json' -d'

{
  "query": { 
    "bool": { 
      "must": [
        { "match": { "book_description": "amazingly realistic" }}
      ],
      "filter": [ 
        { "term":  { "book_status": "published" }}
      ]
    }
  }
}
'

 

Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.

Comments are closed.

What is the difference between Query and Filter in Elasticsearch?
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X