我正在使用搜索查询(查询很长),当我的搜索词是拉丁字符时它可以工作,但一旦我输入一些泰语字符,我就会收到以下错误:
Access to XMLHttpRequest at 'xxxxxxx' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我不明白它与 CORS 策略有何关系,因为相同的查询适用于拉丁字符。 与泰语字符相同的查询在 Kibana 中运行良好。 使用泰语字符作为输入的其他查询(较小)在我的前端也运行良好。
知道什么可能是拦截器吗?
最佳答案
将这些行添加到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
上面的一些选项是默认的,但澄清一下也没有什么坏处。前两行很重要。
更多信息: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html
关于json - Elasticsearch 被 CORS 策略阻止取决于查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64953169/