# Logstash output to redis with dynamic value save in key

**URL:** <https://discuss.elastic.co/t/logstash-output-to-redis-with-dynamic-value-save-in-key/239211>\
**Category:** Logstash\
**Created:** [June 30, 2020, 2:00am UTC](https://discuss.elastic.co/t/logstash-output-to-redis-with-dynamic-value-save-in-key/239211 "2020-06-30T02:00:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kase](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kase](https://discuss.elastic.co/u/kase)\
**Post date:** [June 30, 2020, 2:00am UTC](https://discuss.elastic.co/t/logstash-output-to-redis-with-dynamic-value-save-in-key/239211/1 "2020-06-30T02:00:04Z")

</div>

Hi there,  
[https://www.elastic.co/guide/en/logstash/current/plugins-outputs-redis.html#plugins-outputs-redis-key](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-redis.html#plugins-outputs-redis-key)  
In this doc, it says `key` can save dynamic name, like `logstash-%{type}` .  
I have tried `key => "netflow-%{YYYY.MM.dd}"`  
but when I check redis key, it show me `netflow-%{YYYY.MM.dd}`, doesn't change to `netflow-2020.06.30`

Also, I want to ask that is it possible give field value in elasticsearch to key? If can, is it possible save one by one separately to redis?  
For example, I have 3 document in elasticsearch, like

```auto
  name type
 apple A
 banana B
 orange C

```

and I want to output to redis and save like

```auto
    key value
   apple {"name":"apple","type":"A"}
   banana {"name":"banana","type":"B"}
   orange {"name":"orange","type":"C"}

```

Does anyone know how to solve these problems?  
Thanks  
Kase

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 30, 2020, 3:53pm UTC](https://discuss.elastic.co/t/logstash-output-to-redis-with-dynamic-value-save-in-key/239211/2 "2020-06-30T15:53:26Z")

</div>

> [@kase](#):
>
> key =\> "netflow-%{YYYY.MM.dd}"

Does it work if you change that by adding a plus sign?

```
key => "netflow-%{+YYYY.MM.dd}"

```

---

<div class="post-metadata">

**Author:** ![kase](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kase](https://discuss.elastic.co/u/kase)\
**Post date:** [July 1, 2020, 1:20am UTC](https://discuss.elastic.co/t/logstash-output-to-redis-with-dynamic-value-save-in-key/239211/3 "2020-07-01T01:20:07Z")

</div>

Hi @Badger,  
thanks for your answer, after add plus sign, it have changed to today's date.  
Still trying send document field name to key, I have tried `key => "${+name}"`, but it didn't work.  
Does anyone know how to do this? or it's not possible to do?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 1, 2020, 1:37am UTC](https://discuss.elastic.co/t/logstash-output-to-redis-with-dynamic-value-save-in-key/239211/4 "2020-07-01T01:37:26Z")

</div>

Read [this](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html).

If you want to an "output" option to the value of a field [foo] then use

```
 option => "%{foo}"

```

If you want the output option to be set based on the value of the [@timestamp] value of an event then use

```
option => "something-%{+YYYY.MM.dd}"

```

If you want to an option to be set based on the value of an environment variable then use

```
option => "${envVariable}"
```

---

<div class="post-metadata">

**Author:** ![kase](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kase](https://discuss.elastic.co/u/kase)\
**Post date:** [July 1, 2020, 2:39am UTC](https://discuss.elastic.co/t/logstash-output-to-redis-with-dynamic-value-save-in-key/239211/5 "2020-07-01T02:39:25Z")

</div>

Hi @Badger,  
thanks for your help, this doc really helpful.  
But I still stuck in output field value..., I have fields named `flow.src_addr`, `flow.dst_addr`, `flow.src_port`, and `flow.dst_port`. I saw doc says

If you are referring to a **top-level field** , you can omit the `[]` and simply use `fieldname` . To refer to a **nested field** , you specify the full path to that field: `[top-level field][nested field]`

so I tried this, `key => "${[flow][src_addr]}#|${[flow][dst_addr]}#|${[flow][src_port]}#|${[flow][dst_addr]}"`, but it doesn't change to value, is it because I have over 1 document so logstash don't know which document's value to fill in?  
What I really want to do is use these fields to save documents to redis separately.

---

<div class="post-metadata">

**Author:** ![kase](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kase](https://discuss.elastic.co/u/kase)\
**Post date:** [July 1, 2020, 3:53am UTC](https://discuss.elastic.co/t/logstash-output-to-redis-with-dynamic-value-save-in-key/239211/6 "2020-07-01T03:53:16Z")

</div>

> [@kase](#):
>
> `key => "${[flow][src_addr]}#|${[flow][dst_addr]}#|${[flow][src_port]}#|${[flow][dst_addr]}"`

Okay.....I found mistake that I used "$" not "%", after I modify this, it output value.

---

<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:** [July 29, 2020, 3:53am UTC](https://discuss.elastic.co/t/logstash-output-to-redis-with-dynamic-value-save-in-key/239211/7 "2020-07-29T03:53:25Z")

</div>

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