PHP code example of byng / pimcore-elasticsearch-plugin

1. Go to this page and download the library: Download byng/pimcore-elasticsearch-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

byng / pimcore-elasticsearch-plugin example snippets


// @var $eventManager Zend_EventManager_EventManager
$eventManager->attach(
    "document.elasticsearch.preIndex",
    [__CLASS__, "handlePreIndex"]
);

public static function handlePreIndex(ZendEvent $event)
{
    /** @var Page $document */
    $document = $event->getTarget();
    $params = $event->getParams();

    $params["body"]["page"]["customProperty"] = "something";
}

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);