# Painless SHA1 or other hash in scripted field

**URL:** <https://discuss.elastic.co/t/painless-sha1-or-other-hash-in-scripted-field/268018>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [March 22, 2021, 8:53pm UTC](https://discuss.elastic.co/t/painless-sha1-or-other-hash-in-scripted-field/268018 "2021-03-22T20:53:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanziee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seanziee/32/45151_2.png) [@seanziee](https://discuss.elastic.co/u/seanziee)\
**Post date:** [March 22, 2021, 8:53pm UTC](https://discuss.elastic.co/t/painless-sha1-or-other-hash-in-scripted-field/268018/1 "2021-03-22T20:53:30Z")

</div>

I have seen a few posts recommending to use sha1() from painless but I'm unable to make it work. I have a scripted field where I take 4 fields and want to turn them into a hash:

```auto
     x = doc['1'].value +'&' + doc['timestamp'].value.getMillis()+'&' + doc['2'].value +'&' + doc['3'].value
return x

```

How do I use the sha1() function?

These dont work:  
return x.sha1()  
return sha1(x)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 19, 2021, 8:53pm UTC](https://discuss.elastic.co/t/painless-sha1-or-other-hash-in-scripted-field/268018/2 "2021-04-19T20:53:32Z")

</div>

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