Item.php 1 KB
Newer Older
1 2 3
<?php

namespace yiiunit\data\ar\elasticsearch;
AlexGx committed
4

5
use yii\elasticsearch\Command;
6 7 8 9 10 11 12 13 14 15

/**
 * Class Item
 *
 * @property integer $id
 * @property string $name
 * @property integer $category_id
 */
class Item extends ActiveRecord
{
16 17 18 19
    public static function primaryKey()
    {
        return ['id'];
    }
20

21 22 23 24
    public function attributes()
    {
        return ['id', 'name', 'category_id'];
    }
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    /**
     * sets up the index for this record
     * @param Command $command
     */
    public static function setUpMapping($command)
    {
        $command->deleteMapping(static::index(), static::type());
        $command->setMapping(static::index(), static::type(), [
            static::type() => [
                "_id" => ["path" => "id", "index" => "not_analyzed", "store" => "yes"],
                "properties" => [
                    "name" =>        ["type" => "string", "index" => "not_analyzed"],
                    "category_id" =>      ["type" => "integer"],
                ]
            ]
        ]);
42

43
    }
44
}