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

Matching all the documents


One of the most used queries, usually in conjunction with a filter, is the match all query. This kind of query allows you to return all the documents.

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 match_all query, perform the following steps:

  1. From the command line, execute the query:

    curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{"query":{"match_all":{}}}'
    
  2. The following result should be returned by ElasticSearch if everything works all right:

    {
      "took" : 52,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      },
      "hits" : {
        "total" : 3,
        "max_score" : 1.0,
        "hits" : [{
          "_index" : "test-index",
          "_type" : "test-type",
          "_id" : "1",
          "_score" : 1.0, "_source" : {"position": 1, "parsedtext": "Joe Testere...