# AND in SQL query is translated to nested bool

**URL:** <https://discuss.elastic.co/t/and-in-sql-query-is-translated-to-nested-bool/300923>\
**Category:** Elasticsearch\
**Created:** [March 29, 2022, 8:15am UTC](https://discuss.elastic.co/t/and-in-sql-query-is-translated-to-nested-bool/300923 "2022-03-29T08:15:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![avnere](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@avnere](https://discuss.elastic.co/u/avnere)\
**Post date:** [March 29, 2022, 8:15am UTC](https://discuss.elastic.co/t/and-in-sql-query-is-translated-to-nested-bool/300923/1 "2022-03-29T08:15:35Z")

</div>

Hi,

When I translate the following to DSL I see multiple nested bool instead one bool that contains all the conditions. Can I control it?

```auto
GET _sql/translate
{
  "query": """
   SELECT * FROM "base" 
  WHERE "Id" = '6238caf' AND "stream" LIKE 'rrr' AND "source" = 'WW' AND "name" LIKE 'abc' AND "param1" LIKE 'ccc'
  """,
  "fetch_size": 10000
}

```

Provide:

```auto
"query" : {
    "bool" : {
      "must" : [
        {
          "bool" : {
            "must" : [
              {
                "bool" : {
                  "must" : [
                    {
                      "bool" : {
                        "must" : [
                          {
                            "term" : {
                              "Id" : {
                                "value" : "6238caf",
                                "boost" : 1.0
                              }
                            }
                          },
                          {
                            "term" : {
                              "streamName" : {
                                "value" : "rrr",
                                "boost" : 1.0
                              }
                            }
                          }
                        ],
                        "adjust_pure_negative" : true,
                        "boost" : 1.0
                      }
                    },
                    {
                      "term" : {
                        "source" : {
                          "value" : "WW",
                          "boost" : 1.0
                        }
                      }
                    }
                  ],
                  "adjust_pure_negative" : true,
                  "boost" : 1.0
                }
              },
              {
                "term" : {
                  "name" : {
                    "value" : "abc",
                    "boost" : 1.0
                  }
                }
              }
            ],
            "adjust_pure_negative" : true,
            "boost" : 1.0
          }
        },
        {
          "term" : {
            "param1" : {
              "value" : "ccc",
              "boost" : 1.0
            }
          }
        }
      ],
      "adjust_pure_negative" : true,
      "boost" : 1.0
    }
  },

```

Expected:

```auto
"query": {
    "bool": {
        "must": [
            {"term": { "Id" : "622e624f" }},
            {"term": { "streamName": "rrr"}},
            {"term": { "source": "WWW"}},
            {"term": { "name": "abc"}},
        ]
    }
  }

```

---

<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:** [April 26, 2022, 8:15am UTC](https://discuss.elastic.co/t/and-in-sql-query-is-translated-to-nested-bool/300923/2 "2022-04-26T08:15:42Z")

</div>

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