Hi All,
I am running in to a issue that I am not sure if I am not using it correctly or I need to enable something to get it to work. I had a simple query to that will take the value and checks if the value is greater than the given cutt off number. The data is stored as string, so in the script I am converting that in to an integer. I don't get any exception but I doesn't return any result, it returns with 0 hits. Please let me know what is wrong.
See my steps below for what I did so far.
Thanks,
-Shiv
Elastic Search Version: 1.7.2
-
I enabled the groovy scripting in the elasticsearch.yml file, "script.disable_dynamic: false" and restarted the elastic server.
-
Inserted the following records,
[ { "firstName": "Miguel1", "lastName": "Atkins1", "age": "5" }, { "firstName": "Miguel2", "lastName": "Atkins2", "age": "6" }, { "firstName": "Miguel3", "lastName": "Atkins3", "age": "7" }, { "firstName": "Migue4", "lastName": "Atkins4", "age": "abc" } ]
- Now I try to run the following query,
{ "query": { "filtered": { "filter": { "script": { "script": "try{ if (Integer.parseInt(doc['age'].value) > cutoff) return true; else return false; } catch(Exception e){ return false; }", "lang": "groovy", "params": { "cutoff": 5 } } }, "query": { "match_all": {} } } } }