Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Elasticsearch Form Bundle Laravel Package

alamirault/elasticsearch-form-bundle

View on GitHub
Deep Wiki
Context7

Build Status

Overview

This Symfony bundle allows to create Form and transform fields to an elasticsearch query. Once you created your form type you will be able to update an elasticsearch query from a form type.

The idea is:

  1. Create a form type, foreach field pass option elastic_filter_condition
  2. Use ElasticsearchMaker to submit search, paginate, sort.

Installation

  1. Run composer require alamirault/elasticsearch-form-bundle

  2. Register the bundle in your app/AppKernel.php:

     <?php
     ...
     public function registerBundles()
     {
         $bundles = array(
             ...
             new Alamirault\ElasticsearchBundle\AlamiraultElasticsearchFormBundle(),
             ...
         );
     ...
    

Configuration

alamirault_elasticsearch_form:
    clients:
        default:
            connections:
                - { host: "elasticsearch_host", port: 9200, proxy: null }
            logger: logger.api
            indexes:
                users:
                    mapping: '%kernel.project_dir%/src/Alamirault/LogsBundle/Resources/elasticsearch/mapping/change.yml'

Usage

In ExampleFilterType class:

     public function buildForm(FormBuilderInterface $builder, array $options)
        {
                    $builder->add('uuid', TextType::class, [
                        'elastic_filter_condition' => function (?string $value) {
                            if (is_null($value)) {
                                return;
                            }
        
                            return new Match('uuid', $value);
                        },
                    ])
        }

In controller to make a search page list:

    public function indexAction(Request $request, FormFactoryInterface $formFactory, EntityManagerInterface $entityManager,
                                TranslatorInterface $translator, BoLogEntryDenormalizer $denormalizer)
    {
        $form = $formFactory->create(ExampleFilterType::class);

        $sortableChanges = $this->elasticsearchMaker->manageForm($form, $request, $this->indexRegistry,
            "changes", $denormalizer);

        return $this->render('AlamiraultLogsBundle:Changes:index.html.twig',
            [
                "form" => $form->createView(),
                "sortableChanges" => $sortableChanges,
            ]
        );
    }

Search users by uuid begins by value:

        $matchLike = new Query\Wildcard('uuid', $value."*");
        $query = new Query();
        $query->setQuery($matchLike);
        $query->setSource(["object_uuid"]);

        $resultSet = $this->elasticsearchMaker->makeSearch($this->indexRegistry, "users", $query);

Publish document

            $normalized = $serializer->normalize($user) //User is an object;

            $doc = new Document($user->getUuid(), $normalized);

            $index = $this->indexMaker->getIndex($this->indexRegistry, "users", IndexMaker::WRITE);

            $type = new Type($index, '_doc'); // Only if elasticsearch <7.2.0
            $type->addDocuments([$doc]);

Testing

./vendor/bin/phpunit --bootstrap vendor/autoload.php Tests/
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky