Typesense 问题,错误 "network error"
Issue with Typesense with error "network error"
我正在使用 Reactjs,但在将数据从 Firestore 同步到 Typesense 时遇到了问题。我正在关注此文档,我所做的整个过程都在这里:https://typesense.org/docs/guide/firebase-full-text-search.html#step-1-run-typesense
另外,下面是我在上面link的基础上为我的项目所做的配置。
在我的 Firebase 项目中设置 Cloud Firestore 数据库。
设置 Typesense 服务器(自托管)
通过 API.
设置 Typesense 集合
使用简单的搜索参数查询数据
Instantsearch Adapter 适配器已经安装和配置
问题:它不会呈现数据并出现此错误:Typesense - Network error
代码如下:
import "./App.css";
import { InstantSearch, SearchBox, Hits, Stats } from "react-instantsearch-dom";
import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter";
import Typesense from "typesense";
const client = new Typesense.Client({
nodes: [
{
host: "13.54.222.245", //ip address of the typesense server i have setup on AWS Lightsail
port: "8108",
protocol: "http",
},
],
apiKey: "admin_apikey",
connectionTimeoutSeconds: 2,
});
// creating a collection
const eventData = {
name: "events",
fields: [
{ name: "eventName", type: "string" },
{ name: "eventInfo", type: "string[]" },
],
};
client
.collections()
.create(eventData)
.then(function (data) {
console.log(data);
});
// query the data using search parameters
const search = {
q: "events",
query_by: "eventName",
};
client
.collections("eventData")
.documents()
.search(search)
.then(function (searchResults) {
console.log(searchResults);
});
// search interface for the client side
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
server: {
apiKey: "admin_apikey",
nodes: [
{
host: "127.0.0.1",
port: "8108",
protocol: "https",
},
],
},
additionalSearchParameters: {
queryBy: "eventName, eventInfo",
},
});
const searchClient = typesenseInstantsearchAdapter.searchClient;
function SearchInterface() {
const Hit = ({ hit }) => (
<section class="main">
<div class="card-container">
<div class="card-header">
<h4>{hit.eventName}</h4>
<p>{hit.eventInfo}</p>
</div>
<hr />
</div>
</section>
);
return (
<InstantSearch searchClient={searchClient} indexName="eventData">
<SearchBox />
<Stats />
<Hits hitComponent={Hit} />
</InstantSearch>
);
}
export default SearchInterface;
您在实例化 TypesenseInstantSearchAdapter
时似乎已经配置 nodes
与
交谈
host: "127.0.0.1",
port: "8108",
protocol: "https"
但是根据您在上面使用的配置,您的自托管服务器 运行 位于:
host: "13.54.222.245",
port: "8108",
protocol: "http"
您看到的错误很可能是因为在 127.0.0.1:8108 没有打开 https 的 Typesense 服务器 运行。
我正在使用 Reactjs,但在将数据从 Firestore 同步到 Typesense 时遇到了问题。我正在关注此文档,我所做的整个过程都在这里:https://typesense.org/docs/guide/firebase-full-text-search.html#step-1-run-typesense
另外,下面是我在上面link的基础上为我的项目所做的配置。
在我的 Firebase 项目中设置 Cloud Firestore 数据库。
设置 Typesense 服务器(自托管)
通过 API.
设置 Typesense 集合使用简单的搜索参数查询数据
Instantsearch Adapter 适配器已经安装和配置
问题:它不会呈现数据并出现此错误:Typesense - Network error
代码如下:
import "./App.css";
import { InstantSearch, SearchBox, Hits, Stats } from "react-instantsearch-dom";
import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter";
import Typesense from "typesense";
const client = new Typesense.Client({
nodes: [
{
host: "13.54.222.245", //ip address of the typesense server i have setup on AWS Lightsail
port: "8108",
protocol: "http",
},
],
apiKey: "admin_apikey",
connectionTimeoutSeconds: 2,
});
// creating a collection
const eventData = {
name: "events",
fields: [
{ name: "eventName", type: "string" },
{ name: "eventInfo", type: "string[]" },
],
};
client
.collections()
.create(eventData)
.then(function (data) {
console.log(data);
});
// query the data using search parameters
const search = {
q: "events",
query_by: "eventName",
};
client
.collections("eventData")
.documents()
.search(search)
.then(function (searchResults) {
console.log(searchResults);
});
// search interface for the client side
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
server: {
apiKey: "admin_apikey",
nodes: [
{
host: "127.0.0.1",
port: "8108",
protocol: "https",
},
],
},
additionalSearchParameters: {
queryBy: "eventName, eventInfo",
},
});
const searchClient = typesenseInstantsearchAdapter.searchClient;
function SearchInterface() {
const Hit = ({ hit }) => (
<section class="main">
<div class="card-container">
<div class="card-header">
<h4>{hit.eventName}</h4>
<p>{hit.eventInfo}</p>
</div>
<hr />
</div>
</section>
);
return (
<InstantSearch searchClient={searchClient} indexName="eventData">
<SearchBox />
<Stats />
<Hits hitComponent={Hit} />
</InstantSearch>
);
}
export default SearchInterface;
您在实例化 TypesenseInstantSearchAdapter
时似乎已经配置 nodes
与
host: "127.0.0.1",
port: "8108",
protocol: "https"
但是根据您在上面使用的配置,您的自托管服务器 运行 位于:
host: "13.54.222.245",
port: "8108",
protocol: "http"
您看到的错误很可能是因为在 127.0.0.1:8108 没有打开 https 的 Typesense 服务器 运行。