byng / pimcore-elasticsearch-plugin
Elasticsearch Pimcore plugin
Installs: 1 283
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 12
Forks: 9
Open Issues: 2
Type:pimcore-plugin
Requires
- php: >=5.4
- elasticsearch/elasticsearch: ~2.1
- nineteenfeet/nf-html-to-text: ~1.1
- pimcore/installer-plugin: >=1
- dev-master
- v4.1.1
- v4.1.0
- v4.0.0
- v3.4.0
- 3.3.x-dev
- v3.3.6
- v3.3.5
- v3.3.4
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- 3.2.x-dev
- v3.2.2
- v3.2.1
- v3.2.0
- 3.1.x-dev
- v3.1.0
- 3.0.1
- 3.0.0
- 2.4.x-dev
- 2.4.0
- 2.3.x-dev
- 2.3.0
- 2.2.x-dev
- 2.2.0
- 2.1.x-dev
- 2.1.0
- 2.0.x-dev
- 2.0.0
- 1.1.x-dev
- v1.1.0
- 1.0.x-dev
- 1.0.2
- 1.0.1
- 1.0.0
- dev-add_boost_support
- dev-upgrade-v5
- dev-master_new_filter_query_support
This package is not auto-updated.
Last update: 2024-11-20 16:04:41 UTC
README
The Elasticsearch plugin for Pimcore Saves/updates contents (text only) of document's (editables) and assets to Elasticsearch. It also provides a query builder to search the index.
Features
- Automatic indexing of documents and assets to Elasticsearch when created/updated in Pimcore admin.
- Hooks to add custom properties to the index.
- A simple query builder to retrieve indexed documents. Supports querying, filtering, sorting and pagination.
System Requirements
- PHP - 5.6+
- Elasticsearch - 1.7+
- Pimcore - 3, 4 (not tested on 5 yet)
Installation via composer
The recommended method to install the Pimcore Elasticsearch Plugin is via Composer.
1 - Add byng/pimcore-elasticsearch-plugin
as a dependency in your project's composer.json file and run composer install
2 - Copy the distribution config file (elasticsearchplugin.xml.dist
) in the root of the plugin folder
to {PIMCORE_WEBSITE_DIR}/var/config/elasticsearchplugin.xml
.
3 - Enable the plugin in Pimcore using the extension manager.
Quickstart
Once the installation has been completed, the first time you create or update a document the Elasticsearch index will be created and the document will be indexed. You can verify that the index exists using curl or Kibana.
Hooks
Hooks allow you to hook into the plugin at various points to provide additional functionality. It uses the standard Zend EventManager which Pimcore uses.
Registering an event listener example
For example to register an even listener:
// @var $eventManager Zend_EventManager_EventManager $eventManager->attach( "document.elasticsearch.preIndex", [__CLASS__, "handlePreIndex"] );
The above code will call the handlePreIndex()
method of the class where it was added whenever a document is ready to be indexed.
Within the handlePreIndex()
method you have access to the actual Pimcore document which is being indexed and also the data the plugin has lready extracted. You can add additional properties to the parameters array and they will also be saved to the index:
public static function handlePreIndex(ZendEvent $event) { /** @var Page $document */ $document = $event->getTarget(); $params = $event->getParams(); $params["body"]["page"]["customProperty"] = "something"; }
Available hooks
The following hooks are currently available:
document.elasticsearch.preIndex
This hook is called after the plugin has extracted all the information from the document to index and before it writes the data to Elasticsearch. You can use this hook to write additional/custom properties to the index.
asset.elasticsearch.preIndex
This hook is the asset equivalent of "document.elasticsearch.preIndex".
Querying
The pluigin provides a simple query builder to make it easy to extract information from Elasticsearch.
Example
use Byng\Pimcore\Elasticsearch\Query\BoolQuery; use Byng\Pimcore\Elasticsearch\Query\MatchQuery; use Byng\Pimcore\Elasticsearch\Query\Query; use Byng\Pimcore\Elasticsearch\Query\QueryBuilder; use Byng\Pimcore\Elasticsearch\Gateway\PageGateway; $boolQuery = new BoolQuery(); $boolQuery->addMust(new MatchQuery("_all", "something")); $query = new Query($boolQuery); $queryBuilder = new QueryBuilder(); $queryBuilder->setQuery($query); $queryBuilder->setSize(10); // number of results to return $pageGateway = PageGateway::getInstance(); $resultSet = $pageGateway->query($queryBuilder);
The following JSON request will be generated from the above code and sent to Elasticsearch:
{ "query": { "bool": { "must": [ { "match": { "_all": "something" } } ] } }, "size": 10 }
This will retrieve all documents that contain the word "something".
Todo
- Provide more complete query documentation
- Add support for custom queries, i.e. an array which can be converted to json and posted to Elasticsearch without any processing if the plugin doesn't support the whole Elasticsearch DSL for querying.
License
MIT