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 a match query


ElasticSearch provides a helper to build complex span queries that depend on simple preconfigured settings. This helper is called a match query.

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

  1. The standard usage of a match query simply requires the field name and the query text:

    curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{
      "query": {
        "match" : {
          "parsedtext" : {
            "field": "nice guy",
            "operator": "and"
          }
        }
      }
    }'
    
  2. If you need to execute the same query as a phrase query, the type of match changes in the match_phrase function:

    curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{
      "query": {
        "match_phrase" : {
          "parsedtext" : "nice guy"
        }
      }
    }'
    
  3. An extension of the...