Use composer composer require spameri/elastic
In your config neon, enable extensions. Kdyby/Console is there because we need it to do some command line commands.
extensions:
spameriElasticSearch: \Spameri\Elastic\DI\SpameriElasticSearchExtension
Optionaly you need some Symfony Console implementation ie:
extensions:
console: Kdyby\Console\DI\ConsoleExtension
Then configure where is your ElasticSearch.
spameriElasticSearch:
host: 127.0.0.1
port: 9200
For more config options see default values in \Spameri\Elastic\DI\SpameriElasticSearchExtension::$defaults
. Here.
- After this configuration you are ready to use ElasticSearch in your Nette application.
- Where needed just inject
\Spameri\Elastic\ClientProvider
and then directly call what you need, like this:
$result = $this->clientProvider->client()->search(
(
new \Spameri\ElasticQuery\Document(
$index,
new \Spameri\ElasticQuery\Document\Body\Plain(
$elasticQuery->toArray()
)
)
)->toArray()
);
- Client is provided from elasticsearch/elasticsearch and you can see their documentation what methods and arrays are supported.
- When in doubt what how many arrays or how many arguments match supports use Spameri/ElasticQuery
- This is library used in later examples. But direct approach is also possible.