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": [ ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.