ES 5.2 Scripted Query build from API is not running ,giving error


(JavaES) #1

I am using the following code to build the scripted query

ScriptQueryBuilder sb = new ScriptQueryBuilder( new Script("ctx._source.id=9"));

--> This is producing the following ES query
{
"script" : {
"script" : {
"inline" : "ctx._source.id=9",
"lang" : "painless"
},
"boost" : 1.0
}
}
When I changed to query builder

QueryBuilder qb = QueryBuilders.scriptQuery(new Script("ctx._source.id=9"));

{
"script" : {
"script" : {
"inline" : "ctx._source.id=9",
"lang" : "painless"
},
"boost" : 1.0
}
}
M i missing anything ?

when running the both of the above query's Iam getting the following exception

{"root_cause":[{"type":"illegal_argument_exception","reason":"[script] unknown field [script], parser not found"}],"type":"illegal_argument_exception","reason":"[script] unknown field [script], parser not found"}


(Simon Willnauer) #2

if you pass that to a request body to _search you have to wrap it in a query object:

{
  "query" : {
    "script" : {
      "script" : {
        "inline" : "ctx._source.id=9",
        "lang" : "painless"
      },
    "boost" : 1.0
    }
  }
}

maybe that works for you?


(system) #3

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