Question

Answers

  • user image
    Anurag Srivastava
    Oct 11, 2020, 8:28:32 AM |

    The boolean query is used to search the results on the basis of joining them with 'or', 'and', 'not' conditions. Like joining two conditions with any of them for example:

    "name": "anurag"  and "age": "30"
    "name": "anurag"  or "name": kapil"

    The above examples are just a representation and not the actual Elasticsearch query. Now let's understand how we can achieve the same type of conditions in Elasticsearch. See the below example:

    GET /blogs/technical/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "_type": "technical"
              }
            }
          ],
          "must_not": [
            {
              "match": {
                "topic": "kibana"
              }
            }
          ]
        }
      }
    }
    
    In the above query, I am applying the boolean query by passing the "bool" key after the "query" keyword and then under the "bool" block I have provided two blocks "must" and "must_not". These two blocks have a totally different meaning as "must" is there to ensure the existence of the given condition inside the block while "must_not" is there to ensure the non-existence of the given condition inside on the block. Now under the "must" block I have added a "match" block to match the "_type" key with value as "technical" and under "must_not" I have added, "match" block to match the "topic" with "kibana".

    In this way, we can perform a boolean query in Elasticsearch. If you want to learn more about boolean queries then you can refer to my blog: "Wildcard and Boolean Search in Elasticsearch"

    In case of any queries please leave your comment.
    0 | 0


Related Blogs

preview thumbnail
Introduction to Kibana

Aug 1, 2020, 6:19:45 PM | Anurag Srivastava

preview thumbnail
Bucket Aggregation in Elasticsearch

Aug 29, 2018, 7:15:06 PM | Anurag Srivastava

preview thumbnail
Metrics Aggregations in Elasticsearch

Aug 18, 2018, 6:02:20 PM | Anurag Srivastava

preview thumbnail
Introduction to Elasticsearch Aggregations

Aug 14, 2018, 4:47:56 PM | Anurag Srivastava

preview thumbnail
Wildcard and Boolean Search in Elasticsearch

Aug 10, 2018, 7:14:40 PM | Anurag Srivastava

preview thumbnail
Basics of Data Search in Elasticsearch

Aug 4, 2018, 7:02:21 AM | Anurag Srivastava

Top Blogs

preview thumbnail
Wildcard and Boolean Search in Elasticsearch

Aug 10, 2018, 7:14:40 PM | Anurag Srivastava

preview thumbnail
Elasticsearch REST APIs

Jul 31, 2018, 6:16:42 PM | Anurag Srivastava

preview thumbnail
preview thumbnail
Create a Chess board in PHP

Mar 9, 2020, 8:45:41 AM | Rocky Paul

preview thumbnail
Bucket Aggregation in Elasticsearch

Aug 29, 2018, 7:15:06 PM | Anurag Srivastava

preview thumbnail
Metrics Aggregations in Elasticsearch

Aug 18, 2018, 6:02:20 PM | Anurag Srivastava