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

Using an ID query/filter


The ID query/filter allows you to match documents by their IDs.

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 ID queries/filters, perform the following steps:

  1. The ID query to fetch IDs 1, 2, 3 of the type test-type is in this form:

    curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{
      "query": {
        "ids" : {
          "type" : "test-type",
          "values" : ["1", "2", "3"]
        }
      }
    }'
    
  2. The same query can be converted to a filter query, similar to this one:

    curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{
      "query": {
        "filtered": {
          "filter": {
            "ids" : {
              "type" : "test-type",
              "values" : ["1", "2", "3"]
            }
          },
          "query": {
            "match_all": {}
          }
        }
      }
    }'
    

How it works...

Querying/filtering by...