# Script Params vs Constant Hash in Script

**URL:** <https://discuss.elastic.co/t/script-params-vs-constant-hash-in-script/254163>\
**Category:** Logstash\
**Created:** [November 3, 2020, 2:26pm UTC](https://discuss.elastic.co/t/script-params-vs-constant-hash-in-script/254163 "2020-11-03T14:26:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![git-blame](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/git-blame/32/76804_2.png) [@git-blame](https://discuss.elastic.co/u/git-blame)\
**Post date:** [November 3, 2020, 2:26pm UTC](https://discuss.elastic.co/t/script-params-vs-constant-hash-in-script/254163/1 "2020-11-03T14:26:41Z")

</div>

I need to translate from one set of values to another. I would use the _translate_ filter plugin but I need to keep the original value if no translation is found instead of nil.  
So my code is:

```ruby
TRANSLATE_MAP = {
"foo" => "bar",
"dead" => "beef",
...
}

def filter(event)
  # use TRANSLATE_MAP
  event.set(...)

```

My question is whether it is more efficient with respect to memory, performance, etc. to do it like this or perhaps to pass the map as a _script\_params_ value because I don't know if TRANSLATE\_MAP is created once or every time script is called. Similarly for _script\_params_.

---

<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:** [December 1, 2020, 2:26pm UTC](https://discuss.elastic.co/t/script-params-vs-constant-hash-in-script/254163/2 "2020-12-01T14:26:43Z")

</div>

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