Installation¶
Install the Bundle with Composer¶
In your project directory execute the following command to download the latest stable version:
1 | composer require swp/elastic-search-bundle
|
This command requires you to have Composer installed globally. If it’s not installed globally,
download the .phar
file locally as explained in Composer documentation.
Install ElasticSearch¶
Install ElasticSearch server:
1 | brew install elasticsearch
|
Run ElasticSearch server:
1 | elasticsearch
|
Enable the bundle and its dependencies¶
Enable the bundle and its dependencies
by adding the following lines in the app/AppKernel.php
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | // app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new SWP\Bundle\CoreBundle\SWPCoreBundle(),
// ...
new FOS\ElasticaBundle\FOSElasticaBundle(),
new SWP\Bundle\ElasticSearchBundle\SWPElasticSearchBundle(),
);
// ...
}
// ...
}
|
Note
Make sure you add it after SWPCoreBundle (SWP\Bundle\CoreBundle\SWPCoreBundle()
)
Import config file in your app/config/config.yml file:
1 2 | imports:
- { resource: "@SWPElasticSearchBundle/Resources/config/app/config.yml" }
|
Import routing file in app/config/routing.yml:
1 2 3 | swp_elasticsearch:
resource: "@SWPElasticSearchBundle/Controller/Api"
type: annotation
|
Populate ElasticSearch server¶
Run the below command to index all documents:
1 | bin/console fos:elastic:populate
|
That’s it, the bundle is configured properly now!