# Exclude field from request if it is empty

**URL:** <https://discuss.elastic.co/t/exclude-field-from-request-if-it-is-empty/353410>\
**Category:** Elasticsearch\
**Created:** [February 15, 2024, 8:57pm UTC](https://discuss.elastic.co/t/exclude-field-from-request-if-it-is-empty/353410 "2024-02-15T20:57:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rijexe9501](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rijexe9501](https://discuss.elastic.co/u/rijexe9501)\
**Post date:** [February 15, 2024, 8:57pm UTC](https://discuss.elastic.co/t/exclude-field-from-request-if-it-is-empty/353410/1 "2024-02-15T20:57:21Z")

</div>

Hi all. Please tell me, I have a request like this (request 1) and if field2 in it is empty, then I want to exclude it from the selection so that a request like this will be executed (request 2). How can I do this?

Request 1:

```auto
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              { "match": { "full": "test1 test2 test3" }}
            ]
          }
        },
        {
          "bool": {
            "must": [
              { "match": { "field1": "test1" }},
              { "match": { "field2": "test2" }},
              { "match": { "field3": "test3" }}
            ]
          }
        }
      ]
    }
  }
}

```

Request 2:

```auto
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              { "match": { "full": "test test" }}
            ]
          }
        },
        {
          "bool": {
            "must": [
              { "match": { "field1": "test1" }},
              //{ "match": { "field2": "" }},
              { "match": { "field3": "test3" }}
            ]
          }
        }
      ]
    }
  }
}

```

I'm asking this because I can't delete this field programmatically.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 14, 2024, 8:57pm UTC](https://discuss.elastic.co/t/exclude-field-from-request-if-it-is-empty/353410/2 "2024-03-14T20:57:38Z")

</div>

Closed on March 14, 2024, 8:57pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
