# Logstash elasticsearch output plugin - Populating api\_key from metadata field does not work

**URL:** https://discuss.elastic.co/t/logstash-elasticsearch-output-plugin-populating-api-key-from-metadata-field-does-not-work/263259
**Category:** Logstash
**Created:** [February 4, 2021, 3:13pm UTC](https://discuss.elastic.co/t/logstash-elasticsearch-output-plugin-populating-api-key-from-metadata-field-does-not-work/263259 "2021-02-04T15:13:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vigneshr35](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vigneshr35/32/32636_2.png) [@vigneshr35](https://discuss.elastic.co/u/vigneshr35)
#### Post date: [February 4, 2021, 3:13pm UTC](https://discuss.elastic.co/t/logstash-elasticsearch-output-plugin-populating-api-key-from-metadata-field-does-not-work/263259/1 "2021-02-04T15:13:50Z")

</div>

Hi All,

I am using the elasticsearch output plugin of logstash to post my events to elasticsearch. I am using the api\_key authentication method. It is all working fine until I have the api\_key parameter value hardcoded. For Ex:

> api\_key =\> "xxxxxxxxxxxx:yyyyyyyyyyyyyyyy"

where Xs resemble id and Ys the api\_key generated using the [create api\_key security api](https://www.elastic.co/guide/en/elasticsearch/reference/7.10/security-api-create-api-key.html).

But in my filter I am adding the value to be passed to `api_key` parameter into a metadata field `[@metadata][myapikey]`. The idea is use that in the output plugin as shown below

> output {  
> elasticsearch {  
> hosts =\> ["[https://localhost:9200](https://localhost:9200)"]  
> cacert =\> 'path-to-ca.crt'  
> index =\> "my-index-name"  
> api\_key =\> "%{[@metadata][myapikey]}"  
> ssl =\> true  
> }  
> }

As per my understanding, this should have worked like it would work if we provided the `index` from a metadata field like `index => "%{[@metadata][some-index-name]}"`. I have used this for index names successfully before.

Not sure why the same implementation does not work for `api_key` parameter. I have made sure using stdout plugin that the metadata carries the right value in it, but still see invalid api\_key value message when I run this.

Please help here.

---

<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: [March 4, 2021, 3:13pm UTC](https://discuss.elastic.co/t/logstash-elasticsearch-output-plugin-populating-api-key-from-metadata-field-does-not-work/263259/2 "2021-03-04T15:13:52Z")

</div>

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