# Logstash pipeline Http output plugin error "\[HTTP Output Failure\] Encountered non-2xx HTTP code 400"

**URL:** https://discuss.elastic.co/t/logstash-pipeline-http-output-plugin-error-http-output-failure-encountered-non-2xx-http-code-400/338116
**Category:** Logstash
**Created:** [July 11, 2023, 2:20pm UTC](https://discuss.elastic.co/t/logstash-pipeline-http-output-plugin-error-http-output-failure-encountered-non-2xx-http-code-400/338116 "2023-07-11T14:20:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![PodarcisMuralis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podarcismuralis/32/122606_2.png) [@PodarcisMuralis](https://discuss.elastic.co/u/PodarcisMuralis)
#### Post date: [July 11, 2023, 2:20pm UTC](https://discuss.elastic.co/t/logstash-pipeline-http-output-plugin-error-http-output-failure-encountered-non-2xx-http-code-400/338116/1 "2023-07-11T14:20:58Z")

</div>

Hi all,

I have a logstash output http plugin:

```auto
output {

    if [@metadata][index_to_delete] == "first_index" or [@metadata][index_to_delete] == "second_index" {
        http {
         id => "http_index_delete"
         url => "https://HOST:9200/%{[@metadata][index_to_delete]}"
         http_method => "delete"
         cacert => 'mycert.cer'
         user => "user_with_delete_index_right"
         password => "mypass"
        }
    }
}

```

An I get this error:

```auto
[2023-07-11T16:15:03,083][ERROR][logstash.outputs.http][main][http_index_delete] [HTTP Output Failure] Encountered non-2xx HTTP code 400 {:response_code=>400, :url=>"https://HOST:9200/second_index", :event=>#<LogStash::Event:0x453a6b91>}

```

It is a bad request to elasticsearch.  
How can I solve it? Is it because of credentials? Thank you

Edit: Logstash version 7.17

---

<div class="post-metadata">

### Author: ![PodarcisMuralis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podarcismuralis/32/122606_2.png) [@PodarcisMuralis](https://discuss.elastic.co/u/PodarcisMuralis)
#### Post date: [July 13, 2023, 9:55am UTC](https://discuss.elastic.co/t/logstash-pipeline-http-output-plugin-error-http-output-failure-encountered-non-2xx-http-code-400/338116/2 "2023-07-13T09:55:29Z")

</div>

After days of checking for a solution, I found out that it is a known bug (open issue) in http plugin in logstash output:  
[Link to Github repo http output plugin](https://github.com/logstash-plugins/logstash-output-http/issues/137)

I found a workaround. I used http plugin in the filter section:

```auto
filter {
  if [@metadata][index_to_delete] == "first_index" or [@metadata][index_to_delete] == "second_index" {
          http {
           id => "http_index_delete"
           url => "https://HOST:9200/%{[@metadata][index_to_delete]}"
           verb => "DELETE"
           cacert => 'mycert.cer'
           user => "user_with_delete_index_right"
           password => "mypass"
          }
      }
}

```

It deleted my index in elasticsearch but tried again afterwards. I need to create an if condition to do it once.  
The only difference between filter http plugin and output http plugin is:

```auto
verb => "DELETE"

```

instead of

```auto
http_method => "delete"

```

---

<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 10, 2023, 9:55am UTC](https://discuss.elastic.co/t/logstash-pipeline-http-output-plugin-error-http-output-failure-encountered-non-2xx-http-code-400/338116/3 "2023-08-10T09:55:33Z")

</div>

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