Elasticsearch groovy script to check parameter inclusion in array Elasticsearch groovy script to check parameter inclusion in array elasticsearch elasticsearch

Elasticsearch groovy script to check parameter inclusion in array


This seems to occur due to mismatch in type caused by autoboxing.

The doc['field_name].values for field mapping short, integer, long types seems to be returning a collection always of type 'Long' and the argument to contains is autoboxed to Integercausing contains to fail.

You could probably explictly cast current_user_id to the type of Long:

Example:

doc['recipe_user_ids'].values.contains(new Long(current_user_id))

Or better to use the 'find' method

doc['recipe_user_ids'].values.find {it == current_user_id}