javascript - Elasticsearch https cors enabled but still getting No 'Access-Control-Allow-Origin' header is present on the requested resource -


i have enabled settings cors in index called myindex, here settings it. when try pull data elasticsearch simple javascript cors headers set error

xmlhttprequest cannot load http://elasticsearchdomain.com:9200/myindex/_search/. response preflight request doesn't pass access control check: no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:8000' therefore not allowed access.

i running javascript include script run when open html page through python server.

{       "state": "open",       "settings": {         "index": {           "http": {             "cors": {               "allow-credentials": "true",               "enabled": "true",               "allow-origin": "*"             }           },           "creation_date": "1461087830891",           "number_of_shards": "5",           "number_of_replicas": "1",           "version": {             "created": "1070499"           },           "uuid": "2jeigb7irs6_dzeb6plx-w"         }       },       "mappings": {         "tx": {           "properties": {             "next": {               "format": "dateoptionaltime",               "type": "date"             },             "eid": {               "index": "not_analyzed",               "type": "string"             },             "95percent_time": {               "type": "double"             },             "total_count": {               "type": "long"             },             "failure_count": {               "type": "long"             },             "pool_id": {               "type": "long"             },             "pool_name": {               "index": "not_analyzed",               "type": "string"             },             "failure_rate": {               "type": "double"             },             "report_time": {               "format": "dateoptionaltime",               "type": "date"             },             "txn_type": {               "index": "not_analyzed",               "type": "string"             },             "status_default": {               "type": "long"             },             "txn_name": {               "index": "not_analyzed",               "type": "string"             },             "frequency_type": {               "index": "not_analyzed",               "type": "string"             },             "status_2": {               "type": "long"             },             "status_1": {               "type": "long"             },             "avg_time": {               "type": "double"             },             "datacenter_id": {               "type": "long"             },             "datacenter_name": {               "index": "not_analyzed",               "type": "string"             },             "server_type": {               "type": "string"             }           }         }       },       "aliases": [        ]     } 

here javascript im trying use pull data elasticsearch

var url = "http://elasticsearchdomain.com:9200/myindex/_search/"; var method = "post"; var postdata = '{"query": { "filtered": { "query": { "query_string": { "query": "*", "analyze_wildcard": true } }, "filter": { "bool": { "must": [ { "query": { "query_string": { "query": "*", "analyze_wildcard": true } } }, { "range": { "report_time": { "gte": 1458409392443, "lte": 1461001392443 } } } ], "must_not": [] } } } }, "size": 0, "aggs": { "2": { "date_histogram": { "field": "report_time", "interval": "12h", "pre_zone": "-07:00", "pre_zone_adjust_large_interval": true, "min_doc_count": 1, "extended_bounds": { "min": 1458409392443, "max": 1461001392443 } }, "aggs": { "3": { "terms": { "field": "pool_name", "size": 20, "order": { "_count": "desc" } } } } } } }';  // want async = true. // otherwise, it'll block execution waiting server response. var async = true;  var request = new xmlhttprequest();  // specifies how http response handled.  request.onload = function () {     // can kinds of information http response.    var status = request.status; // http response status, e.g., 200 "200 ok"    var data = request.responsetext; // returned data, e.g., html document. }  request.open(method, url, async); request.setrequestheader('access-control-allow-headers', '*'); request.setrequestheader('access-control-allow-origin', '*'); request.setrequestheader("content-type", "application/json;charset=utf-8");  // sends request server. request.send(postdata); 

those not index specific settings.

the cors settings should placed in elasticsearch.yml config file of every node in es cluster , cluster restarted. see here more this.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -