gpt4 book ai didi

node.js - 仅从搜索中返回 _source

转载 作者:太空宇宙 更新时间:2023-11-04 00:58:35 24 4
gpt4 key购买 nike

当我使用(官方)nodejs-elasticsearch 库执行搜索查询时,是否可以仅检索 _source 文档?根据文档,似乎有一种方法:

Use the /{index}/{type}/{id}/_source endpoint to get just the _source field of the document, without any additional content around it. For example:

curl -XGET 'http://localhost:9200/twitter/tweet/1/_source'

而nodejs库中对应的API调用是:

client.getSource([params, [callback]])

但是,此方法似乎只能根据 ID 检索文档。我需要发出完整的搜索正文(带有过滤器和 query_strings 等),但此方法不支持。

我正在运行 ES 1.4

最佳答案

您可以使用“fields”来实现此目的。请参阅下面的简化示例。继续根据您的要求自定义您的查询:

{
"fields": [
"_source"
],
"query": {
"match_all": {}
}
}

_index_type_id_score 字段的值将始终出现在 Search API 的响应中.

关于node.js - 仅从搜索中返回 _source,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28303134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com