How to solve No Access Control Allow Origin with elastic search

Posted By : Ankush Kocher | 13-Jan-2015

To use elastic search on client side we have to sent Ajax request to crossDomain request to elastic search URL.
localhost:9200 for localhost.

It give following error.

XMLHttpRequest cannot load http://localhost:9200/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
 

This error is with elasticsearch 1.4.2 . when I try to send cross domain Ajax request.

To solve this we have to enable cors in elasticsearch.yml  .

elasticsearch.yml  is in /config/elasticsearch.yml do following changes in this 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
 

we can also use jsonp request method to ride over this error.To allow jsonp request to elastic search 
 uncomment

http.jsonp.enable: true
 

in elasticsearch.yml

ThankYou.

About Author

Author Image
Ankush Kocher

Ankush is a bright web app developer with expertise in Groovy and Grails development. Ankush is also an expert AngularJS developer.

Request for Proposal

Name is required

Comment is required

Sending message..