Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 3, 2020. It is now read-only.

Flexible ElasticSearch Plugin for Pimcore - now with DSL!

NotificationsYou must be signed in to change notification settings

DivanteLtd/pimcore-elasticsearch-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Requirements

  • PHP 7 or newer
  • Pimcore 4
  • Elasticsearch 5
  • Composer

Installation

First step

via Composer

composer require divante-ltd/pimcore-elasticsearch-plugin

manually

  • Download this repository into your plugins directory.
  • Download manually dependencies (see composer.json).
  • Follow next steps in this instruction.

Second step

Open Extension tab in admin panel and install plugin.After this, installation is finished.

Usage

How to use config service?

$container = \Pimcore::getDiContainer();/** @var \DivanteLtd\PimcoreElasticsearchPlugin\Service\ConfigService $configService */$configService = $container->get('DivanteLtd\PimcoreElasticsearchPlugin\Service\ConfigService');$configService->setHosts(["127.0.0.1:9200"]);$indices = [    "exampleIndex" => [        "mappings" => [            "newsType" => [                "properties" => [                    "title" => [                        "type" => "string",                        "analyzer" => "standard"                    ]                ]            ]        ],        //...    ]];foreach ($indices as $indexName => $body) {    $configService->addIndex($indexName, $body);}

INFO: remember config service must be configured before you call elasticsearch service, e.g.: in plugin init method.

Creating index

php pimcore/cli/console.php divante-ltd:elasticsearch:create-index exampleIndex

It will create index in elasticsearch.

INFO: it allows only to create indices which where added to config service.

Removing index

php pimcore/cli/console.php divante-ltd:elasticsearch:remove-index exampleIndex

It will remove index from elasticsearch.

Indexers

use DivanteLtd\PimcoreElasticsearchPlugin\Indexer\AbstractIndexer;class ExampleIndexer extends AbstractIndexer{    /**     * @param AbstractElement $element     *     * @return bool     */    public function isIndexable(AbstractElement $element): bool    {        return $element instanceof News;    }    /**     * @param AbstractElement|News $element     *     * @return array     */    public function buildDocument(AbstractElement $element): array    {        return [            'title' => $element->getTitle(),        ];    }    /**     * @return string     */    public function getIndexName(): string    {        return 'exampleIndex';    }    /**     * @return string     */    public function getType(): string    {        return 'newsType';    }}

You need also to register this indexer, so it can work with reindex all command and event listeners like object.postAdd, etc.

/** @var \DivanteLtd\PimcoreElasticsearchPlugin\Indexer\Service\IndexerRegisterService $indexerRegister */$indexerRegister = \Pimcore::getDiContainer()->get(    'DivanteLtd\PimcoreElasticsearchPlugin\Indexer\Service\IndexerRegisterService');$indexerRegister->add(new ExampleIndexer());

From now everytime you add, edit or delete object which is instance of News class, it will be added, saved or deleted from elastic.

How to reindex everything?

php pimcore/cli/console.php divante-ltd:elasticsearch:reindex-all

If you want to reindex only e.g. objects:

php pimcore/cli/console.php divante-ltd:elasticsearch:reindex-all --objects

How to search?

use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery;use ONGR\ElasticsearchDSL\Query\FullText\MatchQuery;use ONGR\ElasticsearchDSL\Query\TermLevel\TypeQuery;use ONGR\ElasticsearchDSL\Search;use DivanteLtd\PimcoreElasticsearchPlugin\Service\ElasticSearchService;/** @var ElasticSearchService $elasticSearchService */$elasticSearchService = \Pimcore::getDiContainer()->get(    'DivanteLtd\PimcoreElasticsearchPlugin\Service\ElasticSearchService');$boolQuery = new BoolQuery();$boolQuery->addParameter("minimum_should_match", 1);$boolQuery->addParameter("boost", 1);$boolQuery->add(new TypeQuery('newsType'), BoolQuery::MUST);$boolQuery->add(new MatchQuery('title', $query), BoolQuery::SHOULD);$search = new Search();$search    ->addQuery($boolQuery)    ->setFrom(0)    ->setSize(10);//reults should be array of News objects$results = $elasticSearchService->find('newsType', $search);

For more examples take a look here:http://docs.ongr.io/ElasticsearchDSL

About Authors

Divante-logo

We are a Software House from Europe, headquartered in Poland and employing about 150 people. Our core competencies are built around Magento, Pimcore and bespoke software projects (we love Symfony3, Node.js, Angular, React, Vue.js). We specialize in sophisticated integration projects trying to connect hardcore IT with good product design and UX.

Visit our websiteDivante.co for more information.

About

Flexible ElasticSearch Plugin for Pimcore - now with DSL!

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp