jrk*_*rkt 5 cors elasticsearch reactjs reactivesearch
我正在尝试将前端React应用程序与本地elasticsearch节点连接。我正在使用ReactiveSearch连接elasticsearch。我的服务器在Digital Ocean上运行,并且在Ubuntu 16.04上运行。我按照他们的快速入门指南在服务器上运行elasticsearch,并在我的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
我的ReactJS组件看起来就像ReactiveSearch入门说的那样:
<ReactiveBase
app="users"
url="http://localhost:9200">
<DataSearch
componentId="SearchSensor"
dataField={["email", "username", "name"]}
title="Search"
placeholder="Search for users..."
/>
</ReactiveBase>
Run Code Online (Sandbox Code Playgroud)
但是,我收到预检请求标头的CORS错误:
当我尝试访问url:时http://localhost:9200/users/active/_msearch,得到以下响应:
{"error":{"root_cause":[{"type":"parse_exception","reason":"Failed to derive xcontent"}],"type":"parse_exception","reason":"Failed to derive xcontent"},"status":400}
Run Code Online (Sandbox Code Playgroud)
但是,如果我转到url:http://localhost:9200/users/active/1它实际上起作用并显示该对象:
{"_index":"users","_type":"active","_id":"1","_version":1,"found":true,"_source":{ "name": "Jon Stevens", "email": "jon@vendorpay.io" }}
这到底是怎么回事?任何帮助是极大的赞赏!
请求/控制台屏幕快照:
| 归档时间: |
|
| 查看次数: |
406 次 |
| 最近记录: |