Created
September 6, 2018 09:09
-
-
Save factoryhr/6e253f25df4beb5d8c498b40549a2bf3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$movies = Movie::all(); | |
foreach ($movies as $movie) { | |
// Add index and type data to array | |
// Movie::ELASTIC_INDEX => movies | |
// Movie::ELASTIC_TYPE => movie | |
$data['body'][] = [ | |
'index' => [ | |
'_index' => Movie::ELASTIC_INDEX, | |
'_type' => Movie::ELASTIC_TYPE | |
] | |
]; | |
// Movie data that will be required for later search | |
$data['body'][] = [ | |
'id' => $movie->id, | |
'name' => $movie->name, | |
'year' => $movie->year, | |
'description' => $movie->description, | |
'rating' => $movie->rating, | |
'actors' => implode(',', $movie->movie_actors->pluck('name')->toArray()) | |
]; | |
} | |
// Execute Elasticsearch bulk command for indexing multiple data | |
$response = $this->client->bulk($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment