I am trying to do a binary search on a huge array (sorted_keys)
sorted_keys.length = 250,000
my_script = f"""
if (Arrays.binarySearch({sorted_keys}, doc['_meta.key'].value) > 0)) return 0;
return 1;
"""
script = {"script": {"lang": "painless", "source": my_script }}
However this script gives me a compiling error,
elasticsearch7.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'compile error')
According to the docs it should be available https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-api-reference-shared.html#_java_util
How can I use Arrays.binarySearch in painless?
binarySearch is available under Collections
in painless unlike Java
so changing Arrays
to Collections
solved my problem