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

Executing a search


ElasticSearch was born as a search engine; its main work is to process queries and give results.

In this recipe, we'll see that a search in ElasticSearch is not just limited to matching documents but can also calculate additional information required to improve the search quality.

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...

To execute a search and view the results, perform the following steps:

  1. From the command line, execute a search, as follows:

    curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search' -d '{"query":{"match_all":{}}}'
    

    In this case, we have used a match_all query which means that all the documents are returned. We'll discuss this kind of query in the Matching all documents recipe in this chapter.

  2. The command, if everything is all right, will return the following result:

    {
      "took" : 0,
      "timed_out" : false,
      "_shards...