Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.01 KB

File metadata and controls

53 lines (41 loc) · 1.01 KB
endpoint terms_enum
lang javascript
es_version 9.3
client @elastic/elasticsearch@9.3.0

Elasticsearch 9.3 terms_enum endpoint (JavaScript example)

Use client.termsEnum() to retrieve terms matching a prefix from a keyword field. This is designed for autocomplete and typeahead use cases:

const response = await client.termsEnum({
  index: "products",
  field: "category.keyword",
  string: "e",
});

console.log(`Suggestions: ${response.terms}`);

Limiting results

Use size to control how many terms are returned:

const response = await client.termsEnum({
  index: "products",
  field: "name.keyword",
  size: 5,
});

for (const term of response.terms) {
  console.log(`  ${term}`);
}

Case-insensitive matching

Set case_insensitive to match regardless of case:

const response = await client.termsEnum({
  index: "products",
  field: "category.keyword",
  string: "E",
  case_insensitive: true,
});

console.log(`Matches: ${response.terms}`);