'How to execute sql query in elasticsearch Nodejs

Am using Elasticsearch in nodejs using npm elasticsearch,

Here, how can i execute sql queries in elasticsearch?

Is there any npm modules or plugin to execute sql queries in elasticsearch ?



Solution 1:[1]

You can not execute SQL queries directly, but you can convert them to Lucene syntax and execute them so, the where clause would look like

field1:value AND (field2:(a b c) OR field3:[* 5])

you can use the q param to pass the lucene query

       this.client.search({
        index: 'my-index',
        from: 0,
        track_total_hits: true,
        size: 10,
        q: 'field1:value AND (field2:(a b c) OR field3:[* 5])',
        sort: 'field1 ASC'
    });

I would encourage you to look at ANTLR if you want to convert from SQL to Lucene.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Krishna Vedula