Skip to content

Files

Latest commit

98de222 · Oct 26, 2019

History

History
102 lines (66 loc) · 2.53 KB

01_intro.md

File metadata and controls

102 lines (66 loc) · 2.53 KB

Intro

Install

Use composer composer require spameri/elastic

Usage

1. Config ElasticSearch

In your config neon, enable extensions. Kdyby/Console is there because we need it to do some command line commands. Monolog is required by elasticsearch/elasticsearch and we can use existing extension in Kdyby/Monolog.

extensions:
	spameriElasticSearch: \Spameri\Elastic\DI\SpameriElasticSearchExtension
	console: Kdyby\Console\DI\ConsoleExtension
	monolog: Kdyby\Monolog\DI\MonologExtension

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.

Raw client usage

  • 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()
			),
			$index
		)
	)->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.

2. First entity


3. Mapping


4. Fill with data


5. Get data from ElasticSearch


6. Filter data from ElasticSearch


7. Aggregate data from ElasticSearch


x. Other