Response for preflight is invalid (redirect) with AngularJS and ElasticSearch

I'm working on an Angular 1.6.3 app which uses the elasticsearch.js library to query an ElasticSearch 5.4 instance running on a remote server. Recently, our app started having problems where it receives several Response for preflight is invalid (redirect) errors when it initially reaches out to ElasticSearch for data. Currently this problem only happens in Chrome:

Response for preflight is invalid (redirect)

Screenshot of request in Developer Tools:HTTP request in network tab

This error seems to happen randomly, and it doesn't occur when a user accesses the app in Chrome's Incognito Mode or another browser like Firefox.

After doing some research, I found out that this OPTIONS request is a preflight request the browser sends out to ask the server if it's okay to send the actual POST containing what I want to query ElasticSearch for. The reason a preflight is occurring is because I am trying to do a POST with application/json as the Content-Type header, which isn't one of the "standard" values for the Content-Type header.

My question is - how do I resolve this? I've changed the CORS settings in elasticsearch.yml to no avail:

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: "X-Requested-With, X-Auth-Token, Content-Type, Content-Length, Authorization"

I've also tried changing the elasticsearch.js Content-Type headers for each ElasticSearch request but each request continues to send application/json, like the settings don't listen to what I enter:

var client = elasticsearch.Client({
  hosts: [{
    host: '',
    port: 80,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'

A screenshot of the OPTION request that fails from Chrome DevTool net-internals event page:
enter image description here

Any help would be appreciated. Thank you.

1 Like

The cause of problem can be seen in the Chrome DevTool net-internals event page near the bottom of the OPTION request, where it says CHROME_EXTENSION_REDIRECTED_REQUEST. A Chrome extension was randomly redirecting my requests to ElasticSearch, effectively cancelling them. Since it is a Chrome extension that was installed by my company (through an enterprise policy) and thus unremovable, I was able to get the ElasticSearch host added to the extension's whitelist.

1 Like

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