Skip to content

Elasticsearch

ADP provides an ElasticsearchCollectorAppDevPanel\Kernel\Collector\ElasticsearchCollectorCaptures Elasticsearch requests from the application.final Kernel · class · implements SummaryCollectorInterface for capturing Elasticsearch requests during application lifecycle and an inspector for live cluster inspection.

Collector

ElasticsearchCollectorAppDevPanel\Kernel\Collector\ElasticsearchCollectorCaptures Elasticsearch requests from the application.final Kernel · class · implements SummaryCollectorInterface implements SummaryCollectorInterfaceAppDevPanel\Kernel\Collector\SummaryCollectorInterfaceSummary data collector responsibility is to collect summary data for a collector. Summary is used to display a list of previous requests and select one to display full info. Its data set is specific to the list and is reduced compared to full data collected in {@see CollectorInterface}.Kernel · interface · extends CollectorInterface and captures all Elasticsearch requests — searches, indexing, deletions, bulk operations.

Collection Patterns

Two patterns are supported:

Paired pattern — for proxy-based adapters that intercept the ES client:

php
$collector->collectRequestStart($id, 'GET', '/users/_search', $body, $line);
// ... request executes ...
$collector->collectRequestEnd($id, 200, $responseBody, $responseSize);
// or on failure:
$collector->collectRequestError($id, $exception);

Simple pattern — for event-based adapters that measure timing externally:

php
$collector->logRequest(new ElasticsearchRequestRecord(
    method: 'GET',
    endpoint: '/users/_search',
    body: '{"query":{"match_all":{}}}',
    line: __FILE__ . ':' . __LINE__,
    startTime: $start,
    endTime: $end,
    statusCode: 200,
    responseBody: '{"hits":{"total":{"value":42}}}',
    responseSize: 256,
));

Collected Data

php
[
    'requests' => [
        [
            'method' => 'GET',
            'endpoint' => '/users/_search',
            'index' => 'users',           // auto-extracted from endpoint
            'body' => '{"query":{...}}',
            'line' => '/src/Repo.php:42',
            'status' => 'success',         // success | error | initialized
            'startTime' => 1711900000.123,
            'endTime' => 1711900000.135,
            'duration' => 0.012,
            'statusCode' => 200,
            'responseBody' => '...',
            'responseSize' => 256,
            'hitsCount' => 42,             // extracted from response (null for non-search)
            'exception' => null,
        ],
    ],
    'duplicates' => [
        'groups' => [...],                 // repeated method+endpoint combinations
        'totalDuplicatedCount' => 0,
    ],
]

Summary

php
[
    'elasticsearch' => [
        'total' => 3,
        'errors' => 0,
        'totalTime' => 0.045,
        'duplicateGroups' => 0,
        'totalDuplicatedCount' => 0,
    ],
]

Features

Inspector

The Elasticsearch inspector provides live cluster inspection via ElasticsearchProviderInterfaceAppDevPanel\Api\Inspector\Elasticsearch\ElasticsearchProviderInterfaceElasticsearch Provider contract.API · interface.

API Endpoints

MethodPathDescription
GET/inspect/api/elasticsearchCluster health + indices list
GET/inspect/api/elasticsearch/{name}Index detail (mappings, settings, stats)
POST/inspect/api/elasticsearch/searchExecute search query
POST/inspect/api/elasticsearch/queryExecute raw query

Provider Interface

php
interface ElasticsearchProviderInterface
{
    public function getHealth(): array;
    public function getIndices(): array;
    public function getIndex(string $name): array;
    public function search(string $index, array $query, int $limit, int $offset): array;
    public function executeQuery(string $method, string $endpoint, array $body): array;
}

Default: NullElasticsearchProviderAppDevPanel\Api\Inspector\Elasticsearch\NullElasticsearchProviderProvides Null Elasticsearch data.API · class · implements ElasticsearchProviderInterface returns empty data. Adapters provide concrete implementations backed by an actual ES client.

Frontend

Debug Panel

The ElasticsearchPanel displays captured requests with:

  • Method and status code badges (color-coded)
  • Endpoint with extracted index name
  • Duration and hits count per request
  • Expandable request/response body (JSON-rendered)
  • Filter by endpoint, index, method, or body content
  • Duplicate detection warnings

Inspector Page

The ElasticsearchPage shows live cluster state:

  • Cluster health banner (green/yellow/red status chips)
  • Node and shard counts
  • Indices table with docs count, store size, health, shards

Framework Integration

Register ElasticsearchCollectorAppDevPanel\Kernel\Collector\ElasticsearchCollectorCaptures Elasticsearch requests from the application.final Kernel · class · implements SummaryCollectorInterface in your adapter's DI with TimelineCollectorAppDevPanel\Kernel\Collector\TimelineCollectorCollects Timeline data during application lifecycle.final Kernel · class · implements SummaryCollectorInterface as constructor dependency. Enable via config flag 'elasticsearch' => true.

See Adapters for framework-specific registration patterns.

Released under the MIT License.