Hi,
I'm trying to manipulate strings doing an aggregation, but I fail. I've got a field mapped as a keyword, let's call it my_field
. There are some data like 12.0343.13
, 3.253.88
in this field in docs. I try to do the aggregation to find the position of the first dot. My code is
{
"query": {
"bool": {
"filter": [],
"should":[],
"must_not": []
}
},
"aggs": {
"parameter": {
"terms": {
"script" : {
"inline": "doc['my_field'].value.indexOf('.')",
"lang": "painless"
}
}
}
},
"size": 0
}
but instead of a nice aggregation with values like 1, 2, 3 I've got an error
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
],
"script": "doc['my_field'].value.indexOf('.')",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "test_index",
"node": "cXuJC5fxR3GsoK6qHMu2bQ",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
],
"script": "doc['my_field'].value.indexOf('.')",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"status": 500
}
My ES version
"version" : {
"number" : "5.5.2",
"build_hash" : "b2f0c09",
"build_date" : "2017-08-14T12:33:14.154Z",
"build_snapshot" : false,
"lucene_version" : "6.6.0"
}
I cannot use any of the String functions from Painless API Reference - String. I think I miss the idea of using this functions, but I don't know what I'm doing wrong.
Best regards