# Using Environment variable in ES index name

**URL:** <https://discuss.elastic.co/t/using-environment-variable-in-es-index-name/172862>\
**Category:** Beats\
**Created:** [March 18, 2019, 8:32pm UTC](https://discuss.elastic.co/t/using-environment-variable-in-es-index-name/172862 "2019-03-18T20:32:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alsheh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alsheh/32/36799_2.png) [@Alsheh](https://discuss.elastic.co/u/Alsheh)\
**Post date:** [March 18, 2019, 8:32pm UTC](https://discuss.elastic.co/t/using-environment-variable-in-es-index-name/172862/1 "2019-03-18T20:32:42Z")

</div>

I was hopping to use an env variable as part of the index name:

```auto
...
output.elasticsearch:
...
  index: 'auditbeat-${ENVIRONMENT_NAME}-%{[host][name]}-%{+yyyy.MM.dd}'
...

```

But when setting up the Kibana dashboard manually I get:

```auto
Exiting: missing field accessing 'output.elasticsearch.index' (source:'auditbeat.yml')

```

What worked for me is adding the env variable as a field and then use it in the index name:

```auto
...
  fields:
    environment_name: ${ENVIRONMENT_NAME}
...
output.elasticsearch:
...
  index: 'auditbeat-%{[fields][environment_name]}-%{[host][name]}-%{+yyyy.MM.dd}'
...

```

But I'm not interested to store the `[fields][environment_name]` field in ES, is there a work around to achieve this perhaps with storing a temp variable in `@metadata` field?

---

<div class="post-metadata">

**Author:** ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)\
**Post date:** [March 18, 2019, 10:03pm UTC](https://discuss.elastic.co/t/using-environment-variable-in-es-index-name/172862/2 "2019-03-18T22:03:52Z")

</div>

Hmmm, that should've worked.

Can you post the complete command you ran to setup the Kibana dashboards manually? Was `ENVIRONMENT_VARIABLE` set when you ran the command?

---

<div class="post-metadata">

**Author:** ![Alsheh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alsheh/32/36799_2.png) [@Alsheh](https://discuss.elastic.co/u/Alsheh)\
**Post date:** [March 18, 2019, 11:28pm UTC](https://discuss.elastic.co/t/using-environment-variable-in-es-index-name/172862/3 "2019-03-18T23:28:16Z")

</div>

> [@shaunak](#):
>
> Can you post the complete command you ran to setup the Kibana dashboards manually? Was `ENVIRONMENT_VARIABLE` set when you ran the command?

You're right, it worked. The `ENVIRONMENT_VARIABLE ` was set in the Filebeat process but not set in the shell process where I attempted to setup the Kibana dashboards manually which is why it failed initially.

---

<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 16, 2019, 1:28am UTC](https://discuss.elastic.co/t/using-environment-variable-in-es-index-name/172862/4 "2019-04-16T01:28:19Z")

</div>

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