# CORS issue in Elastic Search

**URL:** https://discuss.elastic.co/t/cors-issue-in-elastic-search/45499
**Category:** Elasticsearch
**Created:** [March 26, 2016, 5:55am UTC](https://discuss.elastic.co/t/cors-issue-in-elastic-search/45499 "2016-03-26T05:55:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Priyanka\_Kharote](https://avatars.discourse-cdn.com/v4/letter/p/58f4c7/32.png) [@Priyanka\_Kharote](https://discuss.elastic.co/u/Priyanka_Kharote)
#### Post date: [March 26, 2016, 5:55am UTC](https://discuss.elastic.co/t/cors-issue-in-elastic-search/45499/1 "2016-03-26T05:55:35Z")

</div>

I am consuming Elastic Search Web-service. But I receive  
`XMLHttpRequest cannot load http://<IP>:9200/providers3/provider3/_search. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin "http://localhost:8085" is therefore not allowed access.`

When I put below settings in elasticsearch.yml file

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"

then Elastic search server fails to start.  
Your help would be appreciated.

Thanks.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 26, 2016, 6:13am UTC](https://discuss.elastic.co/t/cors-issue-in-elastic-search/45499/2 "2016-03-26T06:13:45Z")

</div>

Be cautious with yml format.

For example, I think that `http.cors.enabled : true` won't work but `http.cors.enabled: true` should.

HTH

---

<div class="post-metadata">

### Author: ![Priyanka\_Kharote](https://avatars.discourse-cdn.com/v4/letter/p/58f4c7/32.png) [@Priyanka\_Kharote](https://discuss.elastic.co/u/Priyanka_Kharote)
#### Post date: [March 26, 2016, 6:33am UTC](https://discuss.elastic.co/t/cors-issue-in-elastic-search/45499/3 "2016-03-26T06:33:13Z")

</div>

Did changes as you suggested. Now server starting with no errors but CORS issue still exists.

---

<div class="post-metadata">

### Author: ![Priyanka\_Kharote](https://avatars.discourse-cdn.com/v4/letter/p/58f4c7/32.png) [@Priyanka\_Kharote](https://discuss.elastic.co/u/Priyanka_Kharote)
#### Post date: [March 26, 2016, 12:48pm UTC](https://discuss.elastic.co/t/cors-issue-in-elastic-search/45499/4 "2016-03-26T12:48:46Z")

</div>

Resolved above issue. As @dadoonet suggested yml formatting, there was a space issue.  
Below lines are correct, just give a single space before them and CORS issue is solved.

> 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"

Anyone facing same issue can try this.

Thanks

---

<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 5, 2017, 11:04pm UTC](https://discuss.elastic.co/t/cors-issue-in-elastic-search/45499/5 "2017-07-05T23:04:59Z")

</div>


