Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 931 Bytes

File metadata and controls

41 lines (31 loc) · 931 Bytes
endpoint count
lang javascript
es_version 9.3
client @elastic/elasticsearch@9.3.0

Elasticsearch 9.3 count endpoint (JavaScript example)

Use client.count() to get the number of documents matching a query, without returning the documents themselves:

const response = await client.count({
  index: "products",
  query: { term: { category: "electronics" } },
});

console.log(`Electronics: ${response.count}`);

Counting all documents

Omit the query parameter to count all documents in an index:

const response = await client.count({ index: "products" });
console.log(`Total products: ${response.count}`);

Multiple indices

Pass a comma-separated string or an array of index names to count across multiple indices:

const response = await client.count({
  index: ["products", "orders"],
});
console.log(`Total across indices: ${response.count}`);