# Example conversion from SQL to Query DSL

**URL:** <https://discuss.elastic.co/t/example-conversion-from-sql-to-query-dsl/2821>\
**Category:** Elasticsearch\
**Created:** [February 19, 2010, 4:46pm UTC](https://discuss.elastic.co/t/example-conversion-from-sql-to-query-dsl/2821 "2010-02-19T16:46:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [February 19, 2010, 4:46pm UTC](https://discuss.elastic.co/t/example-conversion-from-sql-to-query-dsl/2821/1 "2010-02-19T16:46:54Z")

</div>

Hiya

Structuring queries using the Query DSL is new to me. I've given a  
simple MySQL example, which I've tried to translate into the Query  
DSL.

Please can you tell me if I'm correct, and how I could make it  
simpler, and/or more efficient.

thanks

Clint

```
SELECT id
FROM table
WHERE
            status IN ('active','pending')
          , region = 'south'
          , source = 'south_main'
          , notice_type IN ('family','sales')
          , MATCH("joe bloggs") AGAINST (name,text)
          , publish_date BETWEEN '2010-01-01' AND

```

'2010-01-31'

```
ORDER BY MATCH("joe bloggs") AGAINST (name,text)

{
 sort: { score: {} },
 query: {
    filteredQuery: {
        query: {
            disMax: {
                queries: [
                    { queryString: {
                        query: "joe bloggs",
                        defaultField: "name",
                        boost: 2
                    }},
                    { queryString: {
                        query: "joe bloggs",
                        defaultField: "text",
                        boost: 1
                    }},
        }},
        filter: {
            bool: {
                must: [
                  { term: { region: "south" }},
                  { term: { source: "south_main" }},
                  { disMax: {
                        queries: [
                            { term: { notice_type: "family" }},
                            { term: { notice_type: "sales" }}
                        ]
                  }},
                  { range: {
                        publish_date: {
                            from: "2010-01-01",
                            to: "2010-01-31",
                            includeLower: true,
                            inludeUpper:

```

true  
}  
}}  
],  
}}  
}  
}}

---

<div class="post-metadata">

**Author:** ![gigouni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gigouni/32/9920_2.png) [@gigouni](https://discuss.elastic.co/u/gigouni)\
**Post date:** [August 1, 2016, 12:30pm UTC](https://discuss.elastic.co/t/example-conversion-from-sql-to-query-dsl/2821/2 "2016-08-01T12:30:42Z")

</div>

Hello @Clinton_Gormley

I know that your post is old but the following answer could be useful for someone else because this topic was the top Google answer. I was searching the same thing than you and found out this gem : [https://github.com/NLPchina/elasticsearch-sql/issues/156](https://github.com/NLPchina/elasticsearch-sql/issues/156). I don't know if it could solve someone else problem or even how you solved yours but it's still a good alternative.

An announcement has even been released here : [Announcment: elasticsearch-sql release version 1.2](https://discuss.elastic.co/t/announcment-elasticsearch-sql-release-version-1-2/21391).

Long live ES.

---

<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:** [July 5, 2017, 10:31pm UTC](https://discuss.elastic.co/t/example-conversion-from-sql-to-query-dsl/2821/3 "2017-07-05T22:31:14Z")

</div>


