Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 806 Bytes

File metadata and controls

28 lines (23 loc) · 806 Bytes
endpoint exists_source
lang javascript
es_version 9.3
client @elastic/elasticsearch@9.3.0

Elasticsearch 9.3 exists_source endpoint (JavaScript example)

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");
}

When to use this

This is primarily useful when working with indices where _source may be disabled in the mapping. For most indices, client.exists() is sufficient.