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

Es Lib Laravel Package

awd-studio/es-lib

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation

    composer require awd-studio/es-lib
    

    Publish the config (if available) with:

    php artisan vendor:publish --provider="AwdStudio\EsLib\EsLibServiceProvider"
    
  2. Basic Usage The package provides Elasticsearch utilities. Start by configuring it in config/es-lib.php:

    'connections' => [
        'default' => [
            'hosts' => ['http://localhost:9200'],
            'index' => 'your_app_index',
        ],
    ],
    
  3. First Query Use the Elasticsearch facade to run a simple search:

    use AwdStudio\EsLib\Facades\Elasticsearch;
    
    $results = Elasticsearch::search('your_query', ['index' => 'your_app_index']);
    

Implementation Patterns

Common Workflows

  1. Indexing Models Use the ElasticsearchModel trait to sync Laravel models with Elasticsearch:

    use AwdStudio\EsLib\Traits\ElasticsearchModel;
    
    class Product extends Model
    {
        use ElasticsearchModel;
    
        protected $esIndex = 'products';
    }
    

    Sync data on model events:

    Product::created(fn ($product) => $product->syncToEs());
    
  2. Query Builder Chain methods for complex queries:

    $results = Elasticsearch::search('laptop')
        ->filter('price', '>=', 500)
        ->sortBy('created_at', 'desc')
        ->paginate(10);
    
  3. Bulk Operations Use Elasticsearch::bulk() for batch indexing:

    $data = Product::all()->map(fn ($p) => $p->toEsArray());
    Elasticsearch::bulk($data, 'products');
    

Integration Tips

  • Laravel Scout Alternative: Replace Scout’s Elasticsearch driver with this package for custom logic.
  • Event Listeners: Hook into es-synced or es-failed events for post-sync actions.
  • Middleware: Use EsLibMiddleware to inject Elasticsearch data into requests.

Gotchas and Tips

Pitfalls

  1. Index Mapping Conflicts

    • Ensure your model’s toEsArray() returns fields matching the Elasticsearch mapping. Use Elasticsearch::index()->putMapping() to verify/update mappings.
  2. Rate Limiting

    • Bulk operations may hit Elasticsearch limits. Use Elasticsearch::bulk()->chunk(500) to batch requests.
  3. Connection Timeouts

    • Configure retries in config/es-lib.php:
      'retry' => [
          'max_attempts' => 3,
          'delay' => 100, // ms
      ],
      

Debugging

  • Log Queries: Enable debug mode:
    Elasticsearch::debug(true); // Logs raw queries to storage/logs/es.log
    
  • Test Locally: Use Dockerized Elasticsearch (e.g., docker run -p 9200:9200 elasticsearch:8).

Extension Points

  1. Custom Analyzers Extend the Analyzer class to add domain-specific tokenizers:

    Elasticsearch::analyzer()->custom('custom_analyzer', [
        'type' => 'custom',
        'tokenizer' => 'standard',
        'filter' => ['lowercase', 'asciifolding'],
    ]);
    
  2. Hooks Override syncToEs() in your model to add pre/post-processing:

    protected function prepareForEs()
    {
        $this->esData['slug'] = Str::slug($this->name);
    }
    
  3. Async Processing Use Laravel Queues to offload syncs:

    Product::created(fn ($p) => SyncToEsJob::dispatch($p));
    
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.
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
spatie/mailcoach-vapor