Skip to content

Elasticsearch

sanglt1902 edited this page Jul 16, 2019 · 5 revisions

FIX ERROR 'Access-Control-Allow-Origin'

To use elastic search on client side we have to sent Ajax request to crossDomain request to elastic search URL. localhost:9200 for localhost.

It give following error.

XMLHttpRequest cannot load http://localhost:9200/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. This error is with elasticsearch when I try to send cross domain Ajax request.

To solve this we have to enable cors in elasticsearch.yml .

elasticsearch.yml is in /config/elasticsearch.yml do following changes in this file.

  • 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

we can also use jsonp request method to ride over this error.To allow jsonp request to elasticsearch

  • http.jsonp.enable: true

  • Giới hạn data mỗi query là 10000 link

  • Size trong câu query tính theo index (bắt đầu từ 0)

  • Custom request with aws AWS-Sign

Clone this wiki locally