Hi all,
I plan to get elasticsearch query made by javascript ajax and I made my call like that
$.ajax({
url: "http://localhost:9200/_search?q=dep:10",
type: 'GET',
dataType: 'json',
crossDomain: true,
success: function(data) {
console.log('Success');
$(data.hits.hits).each(function(index, hit) {
console.log(hit._source.items);
});
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
}
});
And I put this in my elasticsearch.yml
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
But I have this error in my console
net::ERR_CONNECTION_REFUSED
Request URL:http://localhost:9200/_search?q=dep:10
Referrer Policy:no-referrer-when-downgrade
Request Headers
Provisional headers are shown
Accept:application/json, text/javascript, */*; q=0.01
Origin:https://domain.com
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.33 Safari/537.36
Query String Parameters
view source
view URL encoded
q:dep:10
I try this to check the setup
root@host4:~# curl -H "User-Agent: Mozilla" -H "Origin: https://domain.com" -i localhost:9200
HTTP/1.1 200 OK
access-control-allow-origin: *
content-type: application/json; charset=UTF-8
content-length: 331
{
"name" : "host4",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "cvaKK5yDSC-Dt_wiSHc4Eg",
"version" : {
"number" : "5.2.2",
"build_hash" : "f9d9b74",
"build_date" : "2017-02-24T17:26:45.835Z",
"build_snapshot" : false,
"lucene_version" : "6.4.1"
},
"tagline" : "You Know, for Search"
}
Thanks for your help, I'm really stuck on this!