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

标签 node.js elasticsearch

当我使用(官方)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/

相关文章:

node.js - Express 4 + pm2 watch 不工作

javascript - setTimeout/Promise.resolve : Macrotask vs Microtask

javascript - 在 Meteor.js 中查找当前 session ID

elasticsearch - 如何使用 Elasticsearch Mapping API 更改现有索引的字段类型

java - 使用语言 Elasticsearch 的多语言搜索

javascript - NextJS : How can I use a loading component instead of nprogress?

node.js - NodeJS 的 Github 操作 - 本地文件的 'Error: Cannot find module'

elasticsearch - Kibana geojson上传卡在创建索引上

elasticsearch - 合并/展平子aggs到主agg

amazon-web-services - 无法从Elasticsearch序列化AWSDate