| endpoint | terms_enum |
|---|---|
| lang | dotnet |
| es_version | 9.3 |
| client | Elastic.Clients.Elasticsearch==9.3.0 |
Use client.TermsEnumAsync() to retrieve terms matching a prefix
from a keyword field. This is designed for autocomplete and
typeahead use cases:
var response = await client.TermsEnumAsync("products", t => t
.Field("category.keyword")
.String("e")
);
Console.WriteLine($"Suggestions: {string.Join(", ", response.Terms)}");Use Size to control how many terms are returned:
var response = await client.TermsEnumAsync("products", t => t
.Field("name.keyword")
.Size(5)
);
foreach (var term in response.Terms)
{
Console.WriteLine($" {term}");
}Set CaseInsensitive to match regardless of case:
var response = await client.TermsEnumAsync("products", t => t
.Field("category.keyword")
.String("E")
.CaseInsensitive(true)
);
Console.WriteLine($"Matches: {string.Join(", ", response.Terms)}");