我正在尝试将我的前端 React 应用程序与本地弹性搜索节点连接起来。我正在使用ReactiveSearch连接弹性搜索。我的服务器在 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>
但是,我收到预检请求标头的 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}
但是,如果我转到 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" }}
这到底是怎么回事??任何帮助是极大的赞赏!
请求/控制台的屏幕截图: