Skip to content

svilborg/elasticsearch-model

Repository files navigation

elasticsearch-model

Elasticsearch Models creation Library

Usage

Simple model definition

class Item extends ModelBase implements Gettable, Indexable, Updatable, Deletable, Searchable
{
    use Get, Index, Update, Delete, Search, Management;

    /**
     *
     * @var string
     */
    protected $index = "inventory";

    /**
     *
     * @var string
     */
    protected $type = "items";

}

Creating a Document

$item = new Item();

 $response = $item->indexDocument(15, [
            "name" => "blue",
            "count" => 24
 ]);

Exended Model Definition

class Item extends ModelBase implements Gettable, Indexable, Updatable, Deletable, Searchable
{
    use Get, Index, Update, Delete, Search, Management;

    /**
     *
     * @var string
     */
    protected $index = "inventory";

    /**
     *
     * @var string
     */
    protected $type = "items";

    protected $settings = [
        'number_of_shards' => 1,
        'number_of_replicas' => 0
    ];

    protected $mapping = [
        '_default_' => [
            'properties' => [
                'name' => [
                    'type' => 'keyword',
                    'copy_to' => 'combined'
                ],
                'count' => [
                    'type' => 'keyword',
                    'copy_to' => 'combined'
                ],
                'combined' => [
                    'type' => 'keyword',
                ]
            ]
        ]
    ];
}

Initlaizing an Index with mapping

$item = new Item();

$response = $item->initIndex();

Releases

No releases published

Packages

No packages published

Languages