Skip to content

Elasticsearch

An overview of available infrastructural code when using Elasticsearch's PHP Api.

Projection Type Registry

An Elasticsearch tailored projection type registry is provided by MsgPhp\Domain\Infrastructure\Elasticsearch\ProjectionTypeRegistry. It works directly with any Client and a known configuration of type information.

  • __construct(Client $client, string $prefix, array $mappings, array $settings = [], LoggerInterface $logger = null)
    • $client: The client to work with
    • $prefix: The index prefix
    • $mappings: Index mappings keyed by type
    • $settings: Index settings keyed by type (use '*' => [...] for default settings)
    • $logger: An optional PSR logger

Basic Example

<?php

use Elasticsearch\Client;
use MsgPhp\Domain\Infrastructure\Elasticsearch\ProjectionTypeRegistry;

// --- SETUP ---

/** @var Client $client */

$typeRegistry = new ProjectionTypeRegistry($client, 'app_dev-', [
    'my_projection' => [
        'some_field' => 'some_type', // defaults to ['type' => 'some_type']
        'other_field' => [ // defaults to ['type' => 'text', ...]
            // ...
        ],
    ],
]);

Projection Repository

An Elasticsearch tailored projection repository is provided by MsgPhp\Domain\Infrastructure\Elasticsearch\ProjectionRepository. It works directly with any Client.

  • __construct(Client $client, string $prefix)
    • $client: The Client to work with
    • $prefix: The index prefix

Basic Example

<?php

use Elasticsearch\Client;
use MsgPhp\Domain\Infrastructure\Elasticsearch\ProjectionRepository;

// --- SETUP ---

/** @var Client $client */

$repository = new ProjectionRepository($client, 'app_dev-');