elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
1.1k stars 24.83k forks source link

Add the ability to hash strings into the watcher context #61244

Closed asjadathick closed 4 years ago

asjadathick commented 4 years ago

Painless in the watcher context does not provide APIs to generate hash values from strings. This is an issue when integrating with external systems that require a unique/key field for documents sent to them.

In my use case, I'm aggregating events on Elasticsearch before sending aggregated results into ServiceNow as CIs (configuration items). Without a hash value, I have no way to update/overwrite existing CIs on servicenow.

I suggest adding support for md5, sha1, sha256 and sha512 methods into the watcher context. Supporting more collision resistant hashes with higher bit lengths will future proof this API.

I suggest the API looks something like this:

def key1 = str1.sha1();
def key2 = "str2".sha1();
def key3 = "str3".md5();
def key4 = "str3".sha256();
elasticmachine commented 4 years ago

Pinging @elastic/es-core-features (:Core/Features/Watcher)

elasticmachine commented 4 years ago

Pinging @elastic/es-core-infra (:Core/Infra/Scripting)

stu-elastic commented 4 years ago

We have that API in the ingest context, see https://github.com/elastic/elasticsearch/pull/59671

The API currently supports sha1 and sha256 as they are guaranteed to be supported in all java implementations. See the MessageDigest documentation for Java 14. Java 8 through Java 13 also includes support for md5 but we've omitted it due to its extreme insecurity.

stu-elastic commented 4 years ago

Added in 7.10