# Query migration to SQL - simplify query

**URL:** <https://discuss.elastic.co/t/query-migration-to-sql-simplify-query/174550>\
**Category:** Elasticsearch\
**Created:** [March 29, 2019, 2:28pm UTC](https://discuss.elastic.co/t/query-migration-to-sql-simplify-query/174550 "2019-03-29T14:28:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdd](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@pdd](https://discuss.elastic.co/u/pdd)\
**Post date:** [March 29, 2019, 2:28pm UTC](https://discuss.elastic.co/t/query-migration-to-sql-simplify-query/174550/1 "2019-03-29T14:28:14Z")

</div>

As Elasticsearch implements SQL-like queries, i'm trying to migarate existing one using Elasticsearch SQL.

Source query:

```
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "foofoo bar",
            "fields": [
              "desc^4",
              "desc.ngram^3"
            ],
            "operator": "AND"
          }
        }
      ],
      "should": [
        {
          "match": {
            "user_id": {
              "query": "222",
              "boost": "2"
            }
          }
        }
      ]
    }
  }
}

```

I've tried to replicate this to Query String Query, that can be passed to QUERY() inside SQL query and ended with:  
`+((+desc:(foofoo )^3 +desc:(bar)^3) | (+desc.ngram:(foofoo )^3 +desc.ngram:(bar)^3)) user_id:(222)^2`

It gives the same result as using normal bool query, but is there any easier way to use it inside SQL query?

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [April 2, 2019, 8:01am UTC](https://discuss.elastic.co/t/query-migration-to-sql-simplify-query/174550/2 "2019-04-02T08:01:03Z")

</div>

Hi @pdd,  
Sorry for the delay here. Shortly put, I don't think there is a different way than the one you used.

In SQL, whenever we have an `AND` or an `OR` we build a `bool` query and we _either_ use `must` statements (for `AND`) or `should` statements (for `OR`). And this is the `[SQL_feature] -> [Elasticsearch_feature]` kind of approach where we implement an sql feature in Elasticsearch.

The way you are looking at this issue, though, is taking an Elasticsearch feature and translate it into SQL world, more or less.  
Thus, this is not so straight forward and you can only do this with the ES specific features in ES-SQL, such as `MATCH()` and `QUERY()` functions.

---

<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 30, 2019, 8:01am UTC](https://discuss.elastic.co/t/query-migration-to-sql-simplify-query/174550/3 "2019-04-30T08:01:05Z")

</div>

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