| endpoint | exists_source |
|---|---|
| lang | javascript |
| es_version | 9.3 |
| client | @elastic/elasticsearch@9.3.0 |
Use client.existsSource() to check whether a document's _source
field exists. Returns false if the document does not exist or if
_source is disabled for the index.
const hasSource = await client.existsSource({ index: "products", id: "prod-1" });
if (hasSource) {
const doc = await client.getSource({ index: "products", id: "prod-1" });
console.log(`Source available: ${doc.name}`);
} else {
console.log("No source available");
}This is primarily useful when working with indices where _source may
be disabled in the mapping. For most indices, client.exists() is
sufficient.