# Join Data from a database to an event based on field value

**URL:** <https://discuss.elastic.co/t/join-data-from-a-database-to-an-event-based-on-field-value/171190>\
**Category:** Logstash\
**Created:** [March 6, 2019, 7:55pm UTC](https://discuss.elastic.co/t/join-data-from-a-database-to-an-event-based-on-field-value/171190 "2019-03-06T19:55:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Becker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simon_becker/32/87100_2.png) [@Simon\_Becker](https://discuss.elastic.co/u/Simon_Becker)\
**Post date:** [March 6, 2019, 7:55pm UTC](https://discuss.elastic.co/t/join-data-from-a-database-to-an-event-based-on-field-value/171190/1 "2019-03-06T19:55:29Z")

</div>

Hi everyone,

i have a pretty complicated problem to solve:  
I would like enrich my datastream that I recieve from applications with metadata. I need this later to create on joined fields user restrictions and so on.  
Every customer needs his own index. Problem is that in my original data I have to join customer names on the hostname, based on a lookup to then forward the data to different indices.

I had a look at the Jdbc\_streaming filter which seems to be the right choice.  
But I cannot find any condition parameter on my values.

My goal is to join on a hostname values like "customer", "location" [...].  
Therefore I need a condition to say if hostname is server1.domain add location:berlin and customer:elastic.  
Pipeline could be like

> input{  
> http{  
> host =\> 123.xy  
> port =\> 8080  
> }  
> }  
> filter{  
> #here I have no idea what to do  
> #DB connection  
> #Then how to join on a field  
> }  
> output{  
> elasticsearch{  
> index=index%customer%  
> ssl =\>enabled  
> user =\> "myuser"  
> passwordd =\> "mysupersecretpassword123!"  
> }  
> }

I have a lot of servers, so i do not want to write for every server a condition.

In case the JDBC connection is not the right choice for this use case, i could switch to a csv file an try it with this.

Has anyone in the community made experience with something like this?

Thank you all 🙂

---

<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:** [March 6, 2019, 10:24pm UTC](https://discuss.elastic.co/t/join-data-from-a-database-to-an-event-based-on-field-value/171190/2 "2019-03-06T22:24:08Z")

</div>

If you create a YAML file containing lines like

```auto
server1.domain: { "location": "berlin", "customer":"elastic" }

```

then you use a translate filter like this:

```
    translate {
        field => "hostname"
        dictionary_path => "/home/user/foo.yml"
    }

```

That will get you an event like

```
   "hostname" => "server1.domain",
"translation" => {
    "customer" => "elastic",
    "location" => "berlin"
},

```

If you want to move the fields from "translation" to the top level then you could use

```
    if [translation] {
        ruby { code => 'event.get("translation").each { |k, v| event.set(k,v) }; event.remove("translation")' }
    }
```

---

<div class="post-metadata">

**Author:** ![Simon\_Becker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simon_becker/32/87100_2.png) [@Simon\_Becker](https://discuss.elastic.co/u/Simon_Becker)\
**Post date:** [March 7, 2019, 10:43am UTC](https://discuss.elastic.co/t/join-data-from-a-database-to-an-event-based-on-field-value/171190/3 "2019-03-07T10:43:40Z")

</div>

Thank you, worked! 😄

---

<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 4, 2019, 10:43am UTC](https://discuss.elastic.co/t/join-data-from-a-database-to-an-event-based-on-field-value/171190/4 "2019-04-04T10:43:44Z")

</div>

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