Closed zkrhm closed 9 years ago
To achieve mappings you will need to add something like following into your Elasticquent model:
protected $mappingProperties = [
id' => [
'type' => 'integer',
],
'name' => [
'type' => 'string',
'analyzer' => 'string_lowercase'
]
];
and in your app you will need to do something like this:
$users = User::all();
$users->rebuildMapping();
hi @yswery thank you for replying. what about index creation can I use migration to do it? since when I use elasticsearch API usually I only need to execute it once.
If you wished for example to do the one off current DB index $users->addToIndex()
for example. You can use a migration to do this, but instead what I ended up doing with mine was creating a command in laravel http://laravel.com/docs/4.2/commands
In theory this will enable you run this manually just like "flushing cache" would be.
After that everytime a new user registers you would index them after your save() method is called for example.
Thanks @yswery - I usually have these set up as commands as well. @zkrhm - you can also definitely use the Elasticsearch API with this - the mapping functionality in Elasticquent is more of just a convenience feature - there is no other processes that go on that cannot just be performed with the PHP API they provide.
As for your second question - you can control what each model stores by overriding the getIndexDocumentData
function. Whenever Elasticquent stores a model's data in Elasticsearch, it uses this function. By default it just returns the array of data, but you can extend it to store whatever custom structure that you'd like to.
hello @adamfairholm , I am fairly new to laravel development so forgive me if I ask a stupid question.
thank you