We are using OpenDistro with elastic search. Before executing the query it is compiled and translated in DSL format. Currently we are passing static SQL queries and each query is compiled before execution.
Let us take an example
SQL:Select * from employee where name='abc';
This query is executed multiple times with only name being different for each execution.
Would like to know if there is a way we can execute query like:
select * from employee where name=?
and ?
is replaced with a parameter at runtime.
This will result in compiling the query only once and only parameter will be replaced during execution.
I looked at the documentation of opendistro but could not find any example of this.
Finally after doing more research I found the documentation link on elastic search. We can execute parameterised queries in the below format:
POST /_sql?format=txt
{
"query": "SELECT * FROM employee WHERE name= ?",
"params": ["Frank Herbert"]
}