# How to create index for each service?

**URL:** <https://discuss.elastic.co/t/how-to-create-index-for-each-service/242821>\
**Category:** APM\
**Tags:** server\
**Created:** [July 28, 2020, 3:51am UTC](https://discuss.elastic.co/t/how-to-create-index-for-each-service/242821 "2020-07-28T03:51:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![seven-yu](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@seven-yu](https://discuss.elastic.co/u/seven-yu)\
**Post date:** [July 28, 2020, 3:51am UTC](https://discuss.elastic.co/t/how-to-create-index-for-each-service/242821/1 "2020-07-28T03:51:01Z")

</div>

I am using version 7.4.0

Apm creates a global index for all services by default：  
apm-%{[beat.version]}-%{+yyyy.MM.dd}

Considering the management of ES storage capacity, I need to analyze the data growth trend of some major services, not the total amount of all services

I want to automatically create an index for each new service. Is there any experience I can refer to?

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [July 28, 2020, 6:02am UTC](https://discuss.elastic.co/t/how-to-create-index-for-each-service/242821/2 "2020-07-28T06:02:09Z")

</div>

Hi @seven-yu, welcome to the forum!

You can change the index name by setting either [output.elasticsearch.index](https://www.elastic.co/guide/en/apm/server/current/elasticsearch-output.html#index-option-es) or [output.elasticsearch.indices](https://www.elastic.co/guide/en/apm/server/current/elasticsearch-output.html#indices-option-es). These configuration variables take an index name "format string", which can reference fields the events. For your use-case, you can include `%{[service.name]}` in the format string to create an index per service.

e.g.

```auto
output.elasticsearch:
  hosts: ["http://localhost:9200"]
  indices:
   - index: "apm-%{[observer.version]}-sourcemap"
      when.contains:
        processor.event: "sourcemap"

   - index: "apm-%{[observer.version]}-onboarding-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "onboarding"

   - index: "apm-%{[observer.version]}-%{[service.name]}-error-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "error"

   - index: "apm-%{[observer.version]}-%{[service.name]}-transaction-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "transaction"

   - index: "apm-%{[observer.version]}-%{[service.name]}-span-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "span"

   - index: "apm-%{[observer.version]}-%{[service.name]}-metric-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "metric"

```

Note that the "onboarding" and "sourcemap" indices are not service-specific, hence I did not include `%{[service.name]}` in their names in this example.

---

<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 18, 2020, 2:08am UTC](https://discuss.elastic.co/t/how-to-create-index-for-each-service/242821/3 "2020-08-18T02:08:27Z")

</div>

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