# Add multiple index per kubernetes metadata for filebeat

**URL:** <https://discuss.elastic.co/t/add-multiple-index-per-kubernetes-metadata-for-filebeat/348082>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [November 27, 2023, 8:15pm UTC](https://discuss.elastic.co/t/add-multiple-index-per-kubernetes-metadata-for-filebeat/348082 "2023-11-27T20:15:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![farhad\_kh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/farhad_kh/32/108251_2.png) [@farhad\_kh](https://discuss.elastic.co/u/farhad_kh)\
**Post date:** [November 27, 2023, 8:15pm UTC](https://discuss.elastic.co/t/add-multiple-index-per-kubernetes-metadata-for-filebeat/348082/1 "2023-11-27T20:15:00Z")

</div>

I have a limited number of index names that I can use for each namespace  
How can I do this using Kubernetes metadata?  
I configured filebeat as below, but red elastic index is not created

```auto
apiVersion: v1
kind: ConfigMap
metadata:
  name: filebeat-config
  namespace: kube-logging
  labels:
    k8s-app: filebeat
    kubernetes.io/cluster-service: "true"
data:
  filebeat.yml: |-
    filebeat.autodiscover:
      providers:
        - type: kubernetes
          host: ${HOSTNAME}
          hints.enabled: true
          labels.dedot: true
          annotations.dedot: true
          templates:
            - condition:
                equals:
                  kubernetes.namespace: test-log #Set the namespace in which your
                equals:
                  kubernetes.namespace: test2 -log #Set the namespace in which your 

 app is running, can add multiple conditions in case of more than 1 namespace.
              config:
                - type: container
                  paths:
                    - /var/log/pods/*_${data.kubernetes.pod.uid}/${data.kubernetes.container.name}/*.log

    processors:
      - add_host_metadata:
      - add_kubernetes_metadata:
          in_cluster: true
    output.elasticsearch:
      hosts: ['${ELASTICSEARCH_HOST:"quickstart-es-http.technical-bigdata-elk-d.svc.cluster.local"}:${ELASTICSEARCH_PORT:"9200"}']
      username: elastic
      password: 1K4Q8ituD2k650PzzyES083q
      protocol: "https"
      ssl.verification_mode: "none"
      index: "1w-sre-%{[kubernetes.pod.labels.app]}"
    setup.template:
      enabled: false

```

I also used the label `kubernetes.pod.labels.app.kubernetes.io/owner` but it didn't help  
Also, to solve the index problem, I used the following configuration, but instead of using the label, it used the name of the filebeat service to create the index.

```auto
              indices:
                - index: "1w-sre-%{[kubernetes.pod.labels.app]}"
                  when.contains:
                       namespace: "test-log"

```

Does anyone have any ideas to solve this problem?

---

<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:** [December 25, 2023, 10:15pm UTC](https://discuss.elastic.co/t/add-multiple-index-per-kubernetes-metadata-for-filebeat/348082/2 "2023-12-25T22:15:16Z")

</div>

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