获取编辑

get API 允许根据 ID 从索引中获取类型化的 JSON 文档。以下示例从名为 game-of-thrones 的索引中获取一个 JSON 文档,该文档的类型为 _doc,ID 值为 '1'

'use strict'

const { Client } = require('@elastic/elasticsearch')
const client = new Client({
  cloud: { id: '<cloud-id>' },
  auth: { apiKey: 'base64EncodedKey' }
})

async function run () {
  await client.index({
    index: 'game-of-thrones',
    id: '1',
    document: {
      character: 'Ned Stark',
      quote: 'Winter is coming.'
    }
  })

  const document = await client.get({
    index: 'game-of-thrones',
    id: '1'
  })

  console.log(document)
}

run().catch(console.log)