jquery - elasticsearch.js client connection refused: Access-Control-Allow-Origin not recognized? -
i've been trying ping locally running elasticsearch using elasticsearch.jquery.min.js , "no living connection" error each time.
eta: in chrome see looks pretty low level "connection refused". i'm developing on macos x, , browser points @ page via http://localhost/~myuserid/sitename/
. i'm accessing localhost:9200
falls under cross domain cors requirements.
i see following error in chrome console:
xmlhttprequest cannot load http://localhost:9200/?hello=elasticsearch!. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost' therefore not allowed access.
per http://enable-cors.org/server_apache.html i've added following /etc/apache2/httpd.conf:
<directory /> header set access-control-allow-origin "localhost:9200" allowoverride none require denied </directory>
and run
$ sudo apachectl -t $ sudo apachectl -k graceful
but error persists. there setting i'm overlooking?
i'm noob elasticsearch.js. there need on elasticsearch side allow client connections browser, or something?
i'm following the book in ping attempt:
var client = new $.es.client({ hosts: 'localhost:9200' }); client.ping( { requesttimeout: infinity, // undocumented params appended query string hello: "elasticsearch!" }, function (error) { if (error) { console.error('elasticsearch cluster down!'); console.error(error); } else { console.log('all well'); } } );
but i'm getting following error(s):
"warning: 2015-10-10t07:00:16z" elasticsearch.jquery.min.js:14:10575 unable revive connection: http://localhost:9200/ "warning: 2015-10-10t07:00:16z" elasticsearch.jquery.min.js:14:10575 no living connections
i can connect using curl on command line fine, pull , insert data, etc.:
$ curl "localhost:9200/_cat/indices?v" health status index pri rep docs.count docs.deleted store.size pri.store.size green open fuddle 1 0 3 0 12.9kb 12.9kb green open faddle 1 0 0 0 144b 144b
eta additional diagnostics. google chrome shows following network traces failing attempt. @ http layer response looks it's happening.
general remote address:[::1]:9200 request url:http://localhost:9200/?hello=elasticsearch! request method:head status code:200 ok response headers content-length:0 content-type:text/plain; charset=utf-8 request headers accept:text/plain, */*; q=0.01 accept-encoding:gzip, deflate, sdch accept-language:en-us,en;q=0.8 connection:keep-alive content-length:0 host:localhost:9200 origin:http://localhost referer:http://localhost/~browsc3/opticon/ user-agent:mozilla/5.0 (macintosh; intel mac os x 10_10_5) applewebkit/537.36 (khtml, gecko) chrome/45.0.2454.101 safari/537.36 query string parameters view url encoded hello:elasticsearch!
the same request in wget:
wget http://localhost:9200/?hello=elasticsearch! --2015-10-10 09:47:13-- http://localhost:9200/?hello=elasticsearch! resolving localhost... ::1, 127.0.0.1 connecting localhost|::1|:9200... connected. http request sent, awaiting response... 200 ok length: 342 [application/json] saving to: 'index.html?hello=elasticsearch!' index.html?hello=elastics 100%[=====================================>] 342 --.-kb/s in 0s 2015-10-10 09:47:13 (65.2 mb/s) - 'index.html?hello=elasticsearch!' saved [342/342]
i'm @ loss go here. see lots of references error on teh googlz, none of circumstances seem remotely similar. feels i'm hitting misconfiguration, can't find indicate is.
well, tough one.
here's fixed it:
per http://enable-cors.org/server_apache.html, in /etc/apache2/httpd.conf
, configure access-control-allow-origin:
<directory /> # add following line enable cors connect local elasticsearch. header set access-control-allow-origin "localhost:9200" allowoverride none require 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 run client.ping
call without error.
Comments
Post a Comment