# Set indices based on a field value

**URL:** <https://discuss.elastic.co/t/set-indices-based-on-a-field-value/69579>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [December 20, 2016, 2:10pm UTC](https://discuss.elastic.co/t/set-indices-based-on-a-field-value/69579 "2016-12-20T14:10:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![YLombardi](https://avatars.discourse-cdn.com/v4/letter/y/43a26b/32.png) [@YLombardi](https://discuss.elastic.co/u/YLombardi)\
**Post date:** [December 20, 2016, 2:10pm UTC](https://discuss.elastic.co/t/set-indices-based-on-a-field-value/69579/1 "2016-12-20T14:10:42Z")

</div>

I'm trying to send my logs to multiple indices based on a field value.  
The exemple in the documentation works fine : [https://www.elastic.co/guide/en/beats/filebeat/5.0/elasticsearch-output.html#\_indices](https://www.elastic.co/guide/en/beats/filebeat/5.0/elasticsearch-output.html#_indices)  
But it is based on the content of the message.

I want to do something like this :

```
indices:
   - index: "functional-%{+yyyy.MM.dd}"
        when.equals:
          document_type: functional-log
   - index: "technichal-%{+yyyy.MM.dd}"
        when.equals:
          document_type: technichal-log
   - index: "other-%{+yyyy.MM.dd}"
        when.equals:
          document_type: other-log

```

The documentation doesn't explain the keyword I can use after the "when" field.  
Currently i'm searching information in filebeat github with no success.

How can I do this indices mapping ? Can I find more information somewhere ?

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [December 20, 2016, 3:11pm UTC](https://discuss.elastic.co/t/set-indices-based-on-a-field-value/69579/2 "2016-12-20T15:11:14Z")

</div>

The conditions available should be the same as what are using with the processors. See [https://www.elastic.co/guide/en/beats/filebeat/5.1/configuration-processors.html#conditions](https://www.elastic.co/guide/en/beats/filebeat/5.1/configuration-processors.html#conditions). Please open a [new issue](https://github.com/elastic/beats/issues/new) in the beats repo so that this gets added to the indices config documentation.

The `when` condition should be at the same indentation level as `index` so move yours to the left a bit.

---

<div class="post-metadata">

**Author:** ![YLombardi](https://avatars.discourse-cdn.com/v4/letter/y/43a26b/32.png) [@YLombardi](https://discuss.elastic.co/u/YLombardi)\
**Post date:** [December 20, 2016, 3:34pm UTC](https://discuss.elastic.co/t/set-indices-based-on-a-field-value/69579/3 "2016-12-20T15:34:36Z")

</div>

Thanks, this works with this configuration :

```
indices:
  - index: "functional-%{+yyyy.MM.dd}"
    when.equals:
      logger_name: "functional"
  - index: "technical-%{+yyyy.MM.dd}"
    when.equals:
      logger_name: "technical"
  - index: "other-%{+yyyy.MM.dd}"
    when.equals:
      logger_name: "other"

```

I open a issue here : [https://github.com/elastic/beats/issues/3227](https://github.com/elastic/beats/issues/3227)

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [December 21, 2016, 12:57pm UTC](https://discuss.elastic.co/t/set-indices-based-on-a-field-value/69579/4 "2016-12-21T12:57:25Z")

</div>

why exactly do you need `indices`? Why didn't you configure:

```auto
  index: '%{[logger_name]}-%{+yyyy.MM.dd}'

```

?

I updated your ticket, so we will properly document `index` setting capabilities.

---

<div class="post-metadata">

**Author:** ![YLombardi](https://avatars.discourse-cdn.com/v4/letter/y/43a26b/32.png) [@YLombardi](https://discuss.elastic.co/u/YLombardi)\
**Post date:** [December 21, 2016, 1:12pm UTC](https://discuss.elastic.co/t/set-indices-based-on-a-field-value/69579/5 "2016-12-21T13:12:58Z")

</div>

Because I didn't know that we can do this "%{[logger\_name]}" in an index name.  
Thanks for this information.

---

<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 18, 2017, 1:13pm UTC](https://discuss.elastic.co/t/set-indices-based-on-a-field-value/69579/6 "2017-01-18T13:13:16Z")

</div>

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