Querying/filtering for a single term

Searching or filtering for a particular term is frequently done. A term query and filter work with exact values and are generally very fast.

The term query/filter can be compared to the equals "=" query in the SQL world (for the fields that are not tokenized).

Getting ready

You need a working ElasticSearch cluster and an index populated with the script chapter_05/populate_query.sh, available in the code bundle for this book.

How to do it...

In order to execute a term query/filter, perform the following steps:

  1. Execute a term query from the command line:
    curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{
      "query": {
        "term": {
          "uuid": "33333"
        }
      }
    }'
    
  2. The following result should be ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.