# Split field and reverse join

**URL:** <https://discuss.elastic.co/t/split-field-and-reverse-join/68169>\
**Category:** Logstash\
**Created:** [December 6, 2016, 12:38pm UTC](https://discuss.elastic.co/t/split-field-and-reverse-join/68169 "2016-12-06T12:38:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![illxjasper](https://avatars.discourse-cdn.com/v4/letter/i/898d66/32.png) [@illxjasper](https://discuss.elastic.co/u/illxjasper)\
**Post date:** [December 6, 2016, 12:38pm UTC](https://discuss.elastic.co/t/split-field-and-reverse-join/68169/1 "2016-12-06T12:38:57Z")

</div>

I am trying to parse appache accesslogs with logstash for a project.

To let elasticsearch search efficiënt I want to reverse the domainname. So for example:

[www.example.com](http://www.example.com) Becomes com.example.www

I tried to split the domainname and reverse that using the logstash mutate plugin. When parsed as is I get a field

```
domainname : "www.example.com"

```

Using settings below I get the following results:

Setting:

```
mutate{
    split => {"domainname" => "."}
    add_field => {"reversed_domainname" => ["%{[domainname][-1]}","%{[domainname][-2]}"]}
    join => {"reversed_domainname" => "."}
}

```

Result:

```
domainname = ["www", "example", "com"]

reversed_domainname =["com", "example"]

```

Everything works as intended untill the join function as seen in the results i dont get com.example

If I remove reversed from the join (split the domainname on "." and join them with "." I get the same results.

```
www.example.com becomes www.example.com

```

How can I join the fields in reversed order as it clearly should work.

---

<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:** [December 7, 2016, 6:48am UTC](https://discuss.elastic.co/t/split-field-and-reverse-join/68169/2 "2016-12-07T06:48:57Z")

</div>

> To let elasticsearch search efficiënt I want to reverse the domainname.

You should probably use the pathname analyzer on the ES side instead.

Contrary to popular belief, the options in a mutate filter are _not_ executed in the order specificed; the order is rather fixed:

> <https://github.com/logstash-plugins/logstash-filter-mutate/blob/v3.1.3/lib/logstash/filters/mutate.rb#L202-L217>

Any `add_field` option executes that the end like for other filters. If you have mutations that depend on each other you need to use multiple mutate filters.

---

<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:** [January 4, 2017, 6:49am UTC](https://discuss.elastic.co/t/split-field-and-reverse-join/68169/3 "2017-01-04T06:49:14Z")

</div>

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