承接 laravel-scout/elasticsearch 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravel-scout/elasticsearch

Composer 安装命令:

composer require laravel-scout/elasticsearch

包简介

Laravel Scout driver for Elasticsearch with advanced features like zero-downtime reindexing and lazy backfill

README 文档

README

A powerful Laravel Scout driver for Elasticsearch with advanced features like zero-downtime reindexing and lazy backfill.

Features

  • Elasticsearch Integration: Full integration with Elasticsearch 8.x
  • Zero-Downtime Reindexing: Update mappings without service interruption
  • Lazy Backfill: Efficiently add new fields to existing documents
  • Advanced Mapping: Custom field mapping support
  • Authentication: Basic authentication and SSL support
  • Artisan Commands: Built-in commands for common operations

Installation

composer require laravel-scout/elasticsearch

Configuration

Add the following to your .env file:

SCOUT_DRIVER=elasticsearch
ELASTICSEARCH_HOST=https://your-elasticsearch-host:9200
ELASTICSEARCH_USER=elastic
ELASTICSEARCH_PASS=your-password
ELASTICSEARCH_INDEX_PREFIX=laravel_scout
ELASTICSEARCH_SSL_VERIFICATION=false

Usage

Basic Setup

  1. Configure Scout in config/scout.php:
'elasticsearch' => [
    'hosts' => [
        env('ELASTICSEARCH_HOST', 'localhost:9200'),
    ],
    'username' => env('ELASTICSEARCH_USER', 'elastic'),
    'password' => env('ELASTICSEARCH_PASS', ''),
    'index_prefix' => env('ELASTICSEARCH_INDEX_PREFIX', 'laravel_scout'),
    'number_of_shards' => env('ELASTICSEARCH_NUMBER_OF_SHARDS', 1),
    'number_of_replicas' => env('ELASTICSEARCH_NUMBER_OF_REPLICAS', 0),
    'ssl_verification' => env('ELASTICSEARCH_SSL_VERIFICATION', false),
],
  1. Make your model searchable:
use Laravel\Scout\Searchable;

class Post extends Model
{
    use Searchable;

    public function toSearchableArray()
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'content' => $this->content,
            'misc' => $this->misc ?? 'others',
        ];
    }

    public function getSearchableMapping()
    {
        return [
            'properties' => [
                'id' => ['type' => 'integer'],
                'title' => [
                    'type' => 'text',
                    'analyzer' => 'standard',
                    'fields' => [
                        'keyword' => ['type' => 'keyword']
                    ]
                ],
                'content' => ['type' => 'text'],
                'misc' => [
                    'type' => 'text',
                    'analyzer' => 'standard',
                    'fields' => [
                        'keyword' => ['type' => 'keyword']
                    ]
                ],
            ]
        ];
    }
}

Artisan Commands

Test Connection

php artisan scout:test-elasticsearch

Create Index

php artisan scout:index posts

Import Data

php artisan scout:import "App\Models\Post"

Zero-Downtime Reindex

php artisan scout:reindex-zero-downtime "App\Models\Post"

Lazy Backfill (Add New Fields)

# Add a new field with default value
php artisan scout:lazy-backfill misc --type=text

# Add a keyword field
php artisan scout:lazy-backfill priority --type=keyword

# Force backfill all documents
php artisan scout:lazy-backfill status --type=keyword --force

Add New Fields and Reindex

# Add new fields and reindex the model
php artisan scout:add-fields-reindex "App\Models\Post"

Large Dataset Reindexing

# Reindex large datasets with batch processing
php artisan scout:reindex-large-dataset "App\Models\Post" --batch-size=1000

Seed Large Dataset

# Seed large datasets for testing
php artisan scout:seed-large-dataset "App\Models\Post" --count=10000

Advanced Features

Zero-Downtime Reindexing

This feature allows you to update Elasticsearch mappings without downtime:

  1. Creates a new index with updated mapping
  2. Reindexes all data from the old index
  3. Switches to the new index seamlessly
  4. Maintains the original index name

Lazy Backfill

Efficiently add new fields to existing documents:

  1. Adds the field to the index mapping
  2. Uses update_by_query to populate existing documents
  3. Sets default values for new fields
  4. No full reindex required

Custom Field Types

Supported field types:

  • text - Full-text search with keyword sub-field
  • keyword - Exact match searches
  • integer - Numeric searches
  • date - Date range queries
  • boolean - Boolean filters
  • float - Decimal searches

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

The MIT License (MIT). Please see License File for more information.

laravel-scout/elasticsearch 适用场景与选型建议

laravel-scout/elasticsearch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 76 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「search」 「elasticsearch」 「driver」 「laravel」 「scout」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 laravel-scout/elasticsearch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 laravel-scout/elasticsearch 我们能提供哪些服务?
定制开发 / 二次开发

基于 laravel-scout/elasticsearch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 76
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-12