Skip to content

Commit c625b90

Browse files
TiagoMaiaLtimgws
authored andcommitted
Add examples for customizing the index name. (#73)
1 parent dbb77a3 commit c625b90

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

readme.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,39 @@ You can also get the type mapping and check if it exists.
245245
Book::getMapping();
246246
```
247247

248+
### Setting a Custom Index Name
249+
250+
By default, Elasticquent will look for the `default_index` key within your configuration file(`config/elasticquent.php`). To set the default value for an index being used, you can edit this file and set the `default_index` key:
251+
252+
```php
253+
return array(
254+
255+
// Other configuration keys ...
256+
257+
/*
258+
|--------------------------------------------------------------------------
259+
| Default Index Name
260+
|--------------------------------------------------------------------------
261+
|
262+
| This is the index name that Elastiquent will use for all
263+
| Elastiquent models.
264+
*/
265+
266+
'default_index' => 'my_custom_index_name',
267+
);
268+
```
269+
270+
If you'd like to have a more dynamic index, you can also override the default configuration with a `getIndexName` method inside your Eloquent model:
271+
272+
```php
273+
function getIndexName()
274+
{
275+
return 'custom_index_name';
276+
}
277+
```
278+
279+
Note: If no index was specified, Elasticquent will use a hardcoded string with the value of `default`.
280+
248281
### Setting a Custom Type Name
249282

250283
By default, Elasticquent will use the table name of your models as the type name for indexing. If you'd like to override it, you can with the `getTypeName` function.

0 commit comments

Comments
 (0)