I\'ve been trying to ping a locally running elasticsearch using elasticsearch.jquery.min.js and I get a \"no living connection\" error each time.
ETA: In Chrome I
Well, that was a tough one.
Here's what fixed it:
Per http://enable-cors.org/server_apache.html, in /etc/apache2/httpd.conf
, configure Access-Control-Allow-Origin:
<Directory />
# Add the following line to enable CORS to connect to local elasticsearch.
Header set Access-Control-Allow-Origin "localhost:9200"
AllowOverride none
Require all denied
</Directory>
Per https://jsbroadcast.com/elastic-search-cors/, in elasticsearch-1.7.0/config/elasticsearch.yml
add:
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 can now run the client.ping
call without any error.
Just adding this to elasticsearch.yml
should work.
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"
You don't need to add anything to Apache.
Put in your elasticsearch.yml configuration file, located in elasticsearch-xxx\config\elasticsearch.yml, the line below
http.cors.enabled: true
and Enable cors in your internet navigator. Restart you elasticsearch server and try again.