我正在尝试将前端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" }}
这到底是怎么回事?任何帮助是极大的赞赏!
请求/控制台屏幕快照:
我想将反应搜索与我自己的普通香草弹性搜索集群一起使用.虽然示例和文档描述了这应该是可能的:ReactiveBase,请参阅urlParam.我得到连接错误和Websocket调用wss://..,看起来像是ReactiveBase尝试连接到appbase.io托管弹性.它还传递凭证代码以及对我的代码中未指定的弹性调用.
是否可以连接到正常弹性,我在哪里可以找到有关如何执行此操作的文档?
这是我的定义ReactiveBase:
<ReactiveBase app="documents"url="https://search-siroop-3jjelqkbvwhzqzsolxt5ujxdxm.eu-central-1.es.amazonaws.com/">
Run Code Online (Sandbox Code Playgroud)
为了实现这个例子,我遵循了ReactiveSearch Quickstart
我正在使用Reactivesearch,并且试图在map函数内分配const变量。具体在.map赞这样:
onAllData(data, streamData) {
return (
<div className="grid">
{
data.map((item) =>
const propertyName = item.productName;
<div className="flex-container card" key={item._id}>
<div className="content">
<p>{propertyName}</p>
</div>
</div>
)
}
);
}
Run Code Online (Sandbox Code Playgroud)
const propertyName = item.productName;给我问题。Error states unexpected token。
可能吗?