Exists
检查文档 /game-of-thrones/1 是否存在。
注意
由于此 API 使用了 HEAD 方法,因此 body 值将是布尔值。
'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 exists = await client.exists({
index: 'game-of-thrones',
id: 1
})
console.log(exists)
}
run().catch(console.log)
- true