| endpoint | terms_enum |
|---|---|
| lang | python |
| es_version | 9.3 |
| client | elasticsearch==9.3.0 |
Use client.terms_enum() to retrieve terms matching a prefix from
a keyword field. This is designed for autocomplete and typeahead
use cases:
response = client.terms_enum(
index="products",
field="category.keyword",
string="e",
)
print(f"Suggestions: {response['terms']}")Use size to control how many terms are returned:
response = client.terms_enum(
index="products",
field="name.keyword",
size=5,
)
for term in response["terms"]:
print(f" {term}")Set case_insensitive=True to match regardless of case:
response = client.terms_enum(
index="products",
field="category.keyword",
string="E",
case_insensitive=True,
)
print(f"Matches: {response['terms']}")