# \[ElasticSearch Output Plugin\] Dynamic User for authentication

**URL:** <https://discuss.elastic.co/t/elasticsearch-output-plugin-dynamic-user-for-authentication/185811>\
**Category:** Logstash\
**Created:** [June 14, 2019, 9:01am UTC](https://discuss.elastic.co/t/elasticsearch-output-plugin-dynamic-user-for-authentication/185811 "2019-06-14T09:01:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![salkonuhannovic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/salkonuhannovic/32/47330_2.png) [@salkonuhannovic](https://discuss.elastic.co/u/salkonuhannovic)\
**Post date:** [June 14, 2019, 9:01am UTC](https://discuss.elastic.co/t/elasticsearch-output-plugin-dynamic-user-for-authentication/185811/1 "2019-06-14T09:01:22Z")

</div>

Hi,

is it possible to set the user in the ElasticSearch output plugin dynamically?

Im trying to retrieve the User Information out of the HTTP Headers which are passed. For the Index its working properly but the User is not getting set.

Here is my config:

```
input {
      http {
            port => 8080
           }
}
output {
  if ("" in [headers][username]) {
      elasticsearch {
                hosts => ["${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}"]
                index => "%{[headers][index]}"
                user => "%{[headers][username]}"
                password => "%{[headers][password]}"
                manage_template => false
       }
  }

}

```

Following Error is shown within the logs:  
`[2019-06-14T08:56:03,944][WARN][logstash.outputs.elasticsearch] Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"http://%2525%257B%255Bheaders%255D%255Busername%255D%257D:xxxxxx@ES-HOST>", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError, :error=>"Got response code '401' contacting Elasticsearch at URL '<ES-HOST>"}`

If I set the User manually it works fine.

Thanks,  
Salko

---

<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:** [June 14, 2019, 1:25pm UTC](https://discuss.elastic.co/t/elasticsearch-output-plugin-dynamic-user-for-authentication/185811/2 "2019-06-14T13:25:06Z")

</div>

> [@salkonuhannovic](#):
>
> index =\> "%{[headers][index]}" user =\> "%{[headers][username]}" password =\> "%{[headers][password]}"

No, you cannot do this. The elasticsearch output establishes a connection and authenticates during startup, it does not wait for an event to come along, so you cannot reference fields from an event in the configuration.

---

<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:** [July 12, 2019, 1:25pm UTC](https://discuss.elastic.co/t/elasticsearch-output-plugin-dynamic-user-for-authentication/185811/3 "2019-07-12T13:25:09Z")

</div>

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