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 and/or/not filters


When building complex queries, some typical Boolean operation filters are required, as they allow you to construct complex filter relations as in the traditional relational database world.

Any query DSL cannot be completed if there is no and, or, or not filter.

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 and/or/not filters, perform the following steps:

  1. Search for documents with parsedtext equal to joe and uuid equal to 11111 in this way:

    curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{
      "query": {
        "filtered": {
          "filter": {
            "and": [
              {
                "term": {
                  "parsedtext":"joe"
                }
              },
              {
                "term": {
                  "uuid":"11111"
                }
              }
            ]
          },
          "query": {
            "match_all...