# Create a new field by extracting data from two existing fields in Logstash

**URL:** <https://discuss.elastic.co/t/create-a-new-field-by-extracting-data-from-two-existing-fields-in-logstash/93054>\
**Category:** Logstash\
**Created:** [July 13, 2017, 4:01pm UTC](https://discuss.elastic.co/t/create-a-new-field-by-extracting-data-from-two-existing-fields-in-logstash/93054 "2017-07-13T16:01:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saifhitawala](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@saifhitawala](https://discuss.elastic.co/u/saifhitawala)\
**Post date:** [July 13, 2017, 4:01pm UTC](https://discuss.elastic.co/t/create-a-new-field-by-extracting-data-from-two-existing-fields-in-logstash/93054/1 "2017-07-13T16:01:23Z")

</div>

I have created two fields from my logs as shown below:

```
names: "LeBron", "Jordan", "Philips", "Samuel"
threepointers: "100", "100", "90", "50"

```

`names` and `threepointers` are both of type `string`. This data has already been extracted from the logs and the log looks something like this:

```
|1 = LeBron| 2 = 100 | 1 = Jordan | 2 = 100 | 1 = Philip | 2 = 90 | 1 = Samuel | 2 = 50 |

```

where I extract all the 1s and 2s using `kv` and `field_split, include_keys` methods and then `mutate` on these numbers to `rename` them to `names` and `threepointers`

I would like to create a new field - `bestplayers` containing all those player names having `threepointers = 100` **only**.  
So, essentially I would like to have a result like this:

`bestplayers: "LeBron", "Jordan"`

Any help would be appreciated! Thanks

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 13, 2017, 7:15pm UTC](https://discuss.elastic.co/t/create-a-new-field-by-extracting-data-from-two-existing-fields-in-logstash/93054/2 "2017-07-13T19:15:34Z")

</div>

There's nothing built-in for this but a ruby filter can do it. Something like this perhaps:

```nohighlight
event.set(
    'bestplayers',
    event.get('names').zip(event.get('threepointers')).select { |p| p[1] == 100 }.map { |p| p[0] })

```

---

<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:** [August 10, 2017, 7:15pm UTC](https://discuss.elastic.co/t/create-a-new-field-by-extracting-data-from-two-existing-fields-in-logstash/93054/3 "2017-08-10T19:15:59Z")

</div>

Closed on August 10, 2017, 7:15pm UTC

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