How i can convert the given SQl query to dsl query?

Sql query

SELECT * FROM USER_DB WHERE (NAME IN('BABU DEV', 'NIKHIL') OR AGE IN(23,45)) AND COUNTRY = 'INDIA' AND STATE ='DELHI';

What about this?

{
  "query": {
    "bool": {
      "should": [
        { "terms": { "NAME": [ "BABU DEV", "NIKHIL" ] } },
        { "terms": { "AGE": [ 23, 45 ] } }
      ],
      "minimum_should_match": 1,
      "must": [
        { "term": { "COUNTRY": "INDIA" } },
        { "term": { "STATE": "DELHI" } }
      ]
    }
  }
}
1 Like

This API can help you with the conversion: SQL Translate API | Elasticsearch Guide [7.17] | Elastic

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