Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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 returned by ElasticSearch if everything works all right:

    {
      "took" : 58,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      },
      "hits" : {
        "total" : 1,
        "max_score" : 0.30685282,
      ...