# Filebeat: Select index based on prospector

**URL:** <https://discuss.elastic.co/t/filebeat-select-index-based-on-prospector/93691>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [July 19, 2017, 5:11am UTC](https://discuss.elastic.co/t/filebeat-select-index-based-on-prospector/93691 "2017-07-19T05:11:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Topping](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brian_topping/32/18860_2.png) [@Brian\_Topping](https://discuss.elastic.co/u/Brian_Topping)\
**Post date:** [July 19, 2017, 5:11am UTC](https://discuss.elastic.co/t/filebeat-select-index-based-on-prospector/93691/1 "2017-07-19T05:11:09Z")

</div>

I am trying to find the best way to set the index name based on the prospector that picked up the log entry. In general, I would like everything to default to `index`, then use `indices` for the specific changes as outlined in [https://www.elastic.co/guide/en/beats/filebeat/5.5/elasticsearch-output.html#\_indices](https://www.elastic.co/guide/en/beats/filebeat/5.5/elasticsearch-output.html#_indices).

I would have thought that using the `when` configuration element of `indices` was the right way to do this, but I can't find documentation on it anywhere, just a few examples on that page. What I imagine doing is adding a tag as a part of the prospector, then searching the tag in the `when` clause.

Will this work? Does documentation for `when` exist yet?

Thanks kindly!

---

<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:** [July 19, 2017, 1:59pm UTC](https://discuss.elastic.co/t/filebeat-select-index-based-on-prospector/93691/2 "2017-07-19T13:59:48Z")

</div>

For simplicity I'd use format strings:

```auto
filebeat.prospectors:
- ...
  fields.class: "nginx"
- ...
  fields.class: "apache"

output.elasticsearch:
  index: '%{[fields.class]-%{+yyyy.MM.dd}'

```

You can use `indices` with when clause. If no when clause matches, the `index` setting will be applied.

Documentation on `when`-clause is available in the 'Conditions' documentation: [https://www.elastic.co/guide/en/beats/filebeat/current/configuration-processors.html#conditions](https://www.elastic.co/guide/en/beats/filebeat/current/configuration-processors.html#conditions)

It's always `when.<condition>:`.

---

<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 16, 2017, 2:00pm UTC](https://discuss.elastic.co/t/filebeat-select-index-based-on-prospector/93691/3 "2017-08-16T14:00:00Z")

</div>

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