Filter field by length

hi there, i tried to select data in condition to have only values with length <= 4 in the feild "src".

elasticsearch version : 6.2.3
kibana version : 6.2.3

that's my script : ( i'm working on kibana )

{
"query": {
"bool": {
"must": {
"script": {
"script": "doc['src'].getValues().length <= 4"
}
}
}
}
}

mapping :

{
"my_index": {
"aliases": {},
"mappings": {
"my_type": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"accountcode": {
"type": "text"
},
"acctid": {
"type": "long"
},
"amaflags": {
"type": "integer"
},
"billsec": {
"type": "integer"
},
"calldate": {
"type": "date"
},
"channel": {
"type": "text"
},
"clid": {
"type": "text"
},
"dcontext": {
"type": "text"
},
"disopsition": {
"type": "text"
},
"disposition": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"dst": {
"type": "text",
"fielddata": true
},
"dstchannel": {
"type": "text"
},
"duration": {
"type": "integer"
},
"lastapp": {
"type": "text"
},
"lastdata": {
"type": "text"
},
"recordingfile": {
"type": "text"
},
"src": {
"type": "text",
"fielddata": true
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"uniqueid": {
"type": "text"
},
"userfield": {
"type": "text"
}
}
}
},
"settings": {
"index": {
"refresh_interval": "-1",
"number_of_shards": "5",
"provided_name": "my_index",
"creation_date": "1523286154821",
"analysis": {
"filter": {
"finnish_stemmer": {
"type": "stemmer",
"language": "finnish"
},
"finnish_stop": {
"type": "stop",
"stopwords": "finnish"
}
},
"analyzer": {
"finnish": {
"filter": [
"lowercase",
"finnish_stop",
"finnish_stemmer"
],
"tokenizer": "standard"
},
"content": {
"type": "custom",
"tokenizer": "whitespace"
}
}
},
"number_of_replicas": "1",
"uuid": "nTnSkq0wSKWdQlRsZYX__Q",
"version": {
"created": "6020399"
}
}
}
}
}

i get this error :

{
"took": 3795,
"timed_out": false,
"_shards": {
"total": 6,
"successful": 5,
"skipped": 0,
"failed": 1,
"failures": [
{
"shard": 0,
"index": ".kibana",
"node": "v6wrGNj1TLW8Kb8A8ZpFoA",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:81)",
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)",
"doc['src'].getValues().length <= 4",
" ^---- HERE"
],
"script": "doc['src'].getValues().length <= 4",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "No field found for [src] in mapping with types []"
}
}
}
]
}

are you querying a specific index or all?
If you run the query like

GET _search

That might explain this error IMO

I run this query in kibana as I said so kibana points directly to my index, the other queries works fine, but the script doesn't.

Do you run that from Kibana dev console ? From elsewhere ?

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