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.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Ankush Kocher
Ankush is a bright web app developer with expertise in Groovy and Grails development. Ankush is also an expert AngularJS developer.