I have a field in Elastic search of type 'keyword' with value = "Quantity <= 10".
"hits": [
{
"_index": "rules1",
"_type": "_doc",
"_id": "zvMleGoBkFxQI52IVKGV",
"_score": 1,
"_source": {
"id": "1",
"criteria1": "Quantity <= 10"
}
},
{
"_index": "rules1",
"_type": "_doc",
"_id": "z_MleGoBkFxQI52ItqFC",
"_score": 1,
"_source": {
"id": "2",
"criteria1": "Quantity <= 20"
}
}
]
I need to filter documents with passing Quantity as one of the parameters. I was using painless script -
{
"query": {
"bool" : {
"filter" : {
"script" : {
"script" : {
"source" : "doc['criteria1'].value",
"lang" : "painless",
"params" : {
"Quantity" : "5"
}
}
}
}
}
}
}
But it is giving an error -
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"doc['criteria1'].value",
" ^---- HERE"
],
"script": "doc['criteria1'].value",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "rules1",
"node": "bYDoLP0hSUuOcp9eEriIqQ",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"doc['criteria1'].value",
" ^---- HERE"
],
"script": "doc['criteria1'].value",
"lang": "painless",
"caused_by": {
"type": "class_cast_exception",
"reason": "cannot cast def [java.lang.String] to boolean"
}
}
}
]
},
"status": 400
}