# Accessing Metafield \_index in Logstash

**URL:** https://discuss.elastic.co/t/accessing-metafield-index-in-logstash/228113
**Category:** Logstash
**Created:** [April 15, 2020, 12:20pm UTC](https://discuss.elastic.co/t/accessing-metafield-index-in-logstash/228113 "2020-04-15T12:20:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![InfiniteLoops](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/infiniteloops/32/47144_2.png) [@InfiniteLoops](https://discuss.elastic.co/u/InfiniteLoops)
#### Post date: [April 15, 2020, 12:20pm UTC](https://discuss.elastic.co/t/accessing-metafield-index-in-logstash/228113/1 "2020-04-15T12:20:18Z")

</div>

I am using this output for Elasticsearch

index =\> "%{[headers][key]}-data-%{+YYYY.MM}"

So it creates a index name with the date added. I am trying to reindex this data through a logstash filter. So I am using the previous index as an input to logstash and trying to output the data to the same name while appending a reindexed value.

index =\> "%{[\_index]}-reindexed"

It says this is a Meta field. Do I need to do something different to access it? I have also tried

index =\> "%{[@metadata][\_index]}-reindexed"

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [April 15, 2020, 2:31pm UTC](https://discuss.elastic.co/t/accessing-metafield-index-in-logstash/228113/2 "2020-04-15T14:31:59Z")

</div>

If you are using an elasticsearch input and want to reference the name of the index from which data was fetched you need to set

```
docinfo => true

```

on the input. And yes, you would reference [@metadata][\_index].

---

<div class="post-metadata">

### Author: ![InfiniteLoops](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/infiniteloops/32/47144_2.png) [@InfiniteLoops](https://discuss.elastic.co/u/InfiniteLoops)
#### Post date: [April 15, 2020, 3:43pm UTC](https://discuss.elastic.co/t/accessing-metafield-index-in-logstash/228113/3 "2020-04-15T15:43:18Z")

</div>

Thanks for the reply. I looked up the documentation on that after your post. I now have

```auto
input {
  elasticsearch {
   hosts => ["address"]
   index => "index-name*"
   docinfo => true
  }
}

filter{
some logic
}

output {
 elasticsearch {
      hosts => ["address"]
      index => "copy-of-production.%{[@metadata][_index]}"
   }
   
     stdout { codec => rubydebug {} }
}

```

I am just getting this as the index name for the output - "copy-of-production.%{[@metadata][\_index]}"

Is there something I am missing. Thanks

---

<div class="post-metadata">

### Author: ![InfiniteLoops](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/infiniteloops/32/47144_2.png) [@InfiniteLoops](https://discuss.elastic.co/u/InfiniteLoops)
#### Post date: [April 15, 2020, 5:12pm UTC](https://discuss.elastic.co/t/accessing-metafield-index-in-logstash/228113/4 "2020-04-15T17:12:10Z")

</div>

Your advice worked this with a newer version of Logstash. Thanks again for the help.

---

<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: [May 13, 2020, 5:12pm UTC](https://discuss.elastic.co/t/accessing-metafield-index-in-logstash/228113/5 "2020-05-13T17:12:12Z")

</div>

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