Creating indexes for Elasticquent in Laravel

- 1 answer

Ad

Do I have to create indexes like this Book::createIndex($shards = null, $replicas = null); for every model in my Laravel project?

I succesfully created App\Law::createIndex($shards = null, $replicas = null);, but when I try to create App\LawType::createIndex($shards = null, $replicas = null); it shows an error:

Elasticsearch\Common\Exceptions\BadRequest400Exception with message '{"error":{" root_cause":[{"type":"index_already_exists_exception","reason":"already exists", "index":"default"}],"type":"index_already_exists_exception","reason":"already ex ists","index":"default"},"status":400}'

Ad

Answer

Ad

Laravel only creates a single index, whose default name is default but a custom name can also be configured via the settings called elasticquent.default_index.

After that, each model will be stored in a different type within that index using putMapping.

Ad
source: stackoverflow.com
Ad