【发布时间】:2019-10-25 17:31:08
【问题描述】:
我正在使用the official module 设置一个包含节点 (v 12.4.0) 和弹性搜索 (7.4.0) 的项目。
我正在尝试使用搜索
import { Client, RequestParams, ApiResponse } from '@elastic/elasticsearch'
const client = new Client({ node: 'http://localhost:9200' })
const params: RequestParams.Search = { index: 'doc', body: { query: { match: { title: "castle" } } } };
const response: ApiResponse = await client.search(params);
这会给出 200 响应,但没有结果。
使用 Postman 尝试相同的操作会返回 1 个结果。
POST http://localhost:9200/doc/_search
{
"query": {
"match": { "title": "castle" }
}
}
我不知道为什么search 函数不起作用。我还测试了get、add 和delete,它们都可以工作。
为了创建索引,我使用了:
await client.indices.create({ index: "doc" });
要添加文档,我使用:
await client.index({
index: 'doc',
body: {
title: "Castle Title",
body: "This is text that is not the title."
}
});
我做错了什么?
【问题讨论】:
标签: node.js elasticsearch