Skip to content

Latest commit

 

History

History
59 lines (47 loc) · 1.14 KB

File metadata and controls

59 lines (47 loc) · 1.14 KB
endpoint terms_enum
lang php
es_version 9.3
client elasticsearch/elasticsearch==9.3.0

Elasticsearch 9.3 terms_enum endpoint (PHP example)

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

$response = $client->termsEnum([
    'index' => 'products',
    'body' => [
        'field' => 'category.keyword',
        'string' => 'e',
    ],
]);

echo 'Suggestions: ' . implode(', ', $response['terms']) . "\n";

Limiting results

Use size to control how many terms are returned:

$response = $client->termsEnum([
    'index' => 'products',
    'body' => [
        'field' => 'name.keyword',
        'size' => 5,
    ],
]);

foreach ($response['terms'] as $term) {
    echo "  $term\n";
}

Case-insensitive matching

Set case_insensitive to match regardless of case:

$response = $client->termsEnum([
    'index' => 'products',
    'body' => [
        'field' => 'category.keyword',
        'string' => 'E',
        'case_insensitive' => true,
    ],
]);

echo 'Matches: ' . implode(', ', $response['terms']) . "\n";