# Cross-Origin Request Blocked

**URL:** <https://discuss.elastic.co/t/cross-origin-request-blocked/181647>\
**Category:** Elasticsearch\
**Created:** [May 17, 2019, 7:55pm UTC](https://discuss.elastic.co/t/cross-origin-request-blocked/181647 "2019-05-17T19:55:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Presto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/presto/32/41346_2.png) [@Presto](https://discuss.elastic.co/u/Presto)\
**Post date:** [May 17, 2019, 7:55pm UTC](https://discuss.elastic.co/t/cross-origin-request-blocked/181647/1 "2019-05-17T19:55:22Z")

</div>

Hello,  
I am attempting to access data from elasticsearch for use in D3. I am running elasticsearch and kibana in docker containers with ports 9200 and 5601 mapped to localhost:9200 and 5601 respectively, and am testing the html and script from a browser on a virtual linux machine that has the docker containers up and running.  
I can access Kibana through the browser. However, when I load my custom page to perform the query, I get the following error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at [http://localhost:9200/file\_index/\_search](http://localhost:9200/file_index/_search). (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

This is in spite of including the following lines in my elasticsearch.yml:

# CORS settings.

http.cors.enabled: true  
http.cors.allow-origin: "\*"  
http.cors.allow-methods : OPTIONS, HEAD, GET, POST

The script attempting to perform the query is below.

//  
// Performs a search request against an Elasticsearch server.  
// @param {string} needle  
// The string to search for.  
// @param {string} filter  
// A string to use to filter by type. For example: 'article';  
//  
function doSearch (needle) {  
var searchHost = '[http://localhost:9200/file\_index/\_search](http://localhost:9200/file_index/_search)';  
var body = {  
'size': 20  
};

```
  var query = {
    'bool': {}
  };

    query.bool.must = {
      'multi_match': {
        'query': needle,
        'fields': ['UUID']
      }
    };

  body.query = query;

// Perform the request.
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('POST', searchHost, false);
xmlHttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
xmlHttp.send(JSON.stringify(body));
var response = JSON.parse(xmlHttp.responseText);
// Print results on screen.
var output = '';
for (var i = 0; i < response.hits.hits.length; i++) {
  output += '<h3>' + response.hits.hits[i]._source.title + '</h3>';
  output += response.hits.hits[i]._source.summary_processed[0] + '</br>';
}
document.getElementById('total').innerHTML = '<h2>Showing ' + response.hits.hits.length + ' results</h2>';
document.getElementById('hits').innerHTML = output;

```

}  
doSearch('ddbec291-574d-483f-b8d1-f88ea844c49b');

Any insights are appreciated.

---

<div class="post-metadata">

**Author:** ![Presto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/presto/32/41346_2.png) [@Presto](https://discuss.elastic.co/u/Presto)\
**Post date:** [May 20, 2019, 3:32pm UTC](https://discuss.elastic.co/t/cross-origin-request-blocked/181647/2 "2019-05-20T15:32:18Z")

</div>

Solved: The docker-compose.yml was misplacing the elasticsearch.yml file in the container running elasticsearch, so the CORS settings were not being seen by elasticsearch.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 20, 2019, 5:12pm UTC](https://discuss.elastic.co/t/cross-origin-request-blocked/181647/3 "2019-05-20T17:12:40Z")

</div>

Thanks for sharing your solution 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 17, 2019, 5:12pm UTC](https://discuss.elastic.co/t/cross-origin-request-blocked/181647/4 "2019-06-17T17:12:44Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
