I want to achieve the equivalent of the following SQL query using inline scripts of ES (painless language) :
where userId in (1, 2, 3) ----> Here userId is a long field
I tried with the following :
POST ride/ride/_search
{
"query": {
"bool": {
"filter": [
{
"script": {
"script": {
"source": "doc['userId'].value in [1, 2, 3]"
}
}
}
]
}
}
}
but saw an error :
"caused_by": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"doc['userId'].value in [1, 2, 3]",
" ^---- HERE"
],
"script": "doc['userId'].value in [1, 2, 3]",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "invalid sequence of tokens near ['in'].",
"caused_by": {
"type": "no_viable_alt_exception",
"reason": null
}
}
}
Is there a way to achieve this using inline scripts? I know that this can be achieved using terms, but I am looking for a way to add this as part of another inline script query.
I want to include this as a sub-query in another script which has several other conditions which I could not model without using the scripts. Some distinct part of the existing inline query is shown below :
To be honest, I tried a lot writing a terms query first, but I couldn't figure out how to design my query to match the above. Later I found inline scripts section and prepared a query to match the above constraints. I couldn't identify how to mix && and|| together and also include max(field1, constant1) in the same query!
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.