首页 > 解决方案 > 如何使用新的 elasticsearch typescript 类型

问题描述

我想根据这个 TypeScript 支持使用新的弹性搜索类型 | Elasticsearch Node.js 客户端 [7.x] | 弹性 1 文件,但如果我这样做

// try the new code completion when building a query!
const response = await client.search<Source>({
  index: 'test',
  body: {
    query: {
      match_all: {}
    }
  }
})

// try the new code completion when traversing a response!
const results = response.body.hits.hits.map(hit => hit._source)
// results type will be `Source[]`
console.log(results)

我的结果对象本身是我提供的类型而不是 SearchResponse

标签: typescriptelasticsearch

解决方案


需要使用elasticsearch节点模块版本>=7.13才能使用新类型支持


推荐阅读