Terms enum API
The terms enum API can be used to discover terms in the index that match a partial string. Supported field types are keyword, constant_keyword, flattened, version and ip. This is used for auto-complete:
resp = client.terms_enum(
index="stackoverflow",
field="tags",
string="kiba",
)
print(resp) response = client.terms_enum(
index: 'stackoverflow',
body: {
field: 'tags',
string: 'kiba'
}
)
puts response const response = await client.termsEnum({
index: "stackoverflow",
field: "tags",
string: "kiba",
});
console.log(response); POST stackoverflow/_terms_enum
{
"field" : "tags",
"string" : "kiba"
} The API returns the following response:
{
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"terms": [
"kibana"
],
"complete" : true
} If the complete flag is false, the returned terms set may be incomplete and should be treated as approximate. This can occur due to a few reasons, such as a request timeout or a node error.
The terms enum API may return terms from deleted documents. Deleted documents are initially only marked as deleted. It is not until their segments are merged that documents are actually deleted. Until that happens, the terms enum API will return terms from these documents.
Request
GET /<target>/_terms_enum
Description
The terms_enum API can be used to discover terms in the index that begin with the provided string. It is designed for low-latency look-ups used in auto-complete scenarios.
Path parameters
-
<target> - (Required, string) Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (
*). To search all data streams or indices, omit this parameter or use*or_all.
Request body
-
field - (Mandatory, string) Which field to match
-
string - (Optional, string) The string to match at the start of indexed terms. If not provided, all terms in the field are considered.
The prefix string cannot be larger than the larges possible keyword value, which is Lucene’s term byte-length limit of 32766
-
size - (Optional, integer) How many matching terms to return. Defaults to 10
-
timeout - (Optional, time value) The maximum length of time to spend collecting results. Defaults to "1s" (one second). If the timeout is exceeded the
completeflag set to false in the response and the results may be partial or empty.
-
case_insensitive - (Optional, boolean) When true the provided search string is matched against index terms without case sensitivity. Defaults to false.
-
index_filter - (Optional, query object Allows to filter an index shard if the provided query rewrites to
match_none.
-
search_after - (Optional, string) The string after which terms in the index should be returned. Allows for a form of pagination if the last result from one request is passed as the
search_afterparameter for a subsequent request.
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/search-terms-enum.html