PHPackages                             xander/php-es - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. xander/php-es

ActiveLibrary

xander/php-es
=============

custom php es

v1.1.0(3y ago)04MITPHPPHP ^7.0

Since Jun 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ChinaXander/es-7.0)[ Packagist](https://packagist.org/packages/xander/php-es)[ RSS](/packages/xander-php-es/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

使用 php + es
-----------

[](#使用-php--es)

> 场景一：
>
> 第一次使用时，部署好es后，配置config

```
$config = [
    'host' => ['192.168.0.52:9200'],//es地址
    'index' => 'wares_v3',          //索引名称
];

$es = new  es\ElasticsearchService( $config['host'], $config['index'] );

//创建索引
if(!$es->isCreate()){
    //创建索引配置，具体可以查看es文档
    $es->isCreate([
        'body' => [
            'settings' => [
                'analysis' => [
                    //配置分析器
                    'analyzer' => [
                        //IK分词器+拼音分词过滤器+内置ngram分词过滤器
                        'ik_max_word_analyzer' => [
                            'tokenizer' => 'ik_max_word',//ik_max_word-细粒度分词
                            'filter' => ['icfilter', 'my_pinyin', 'unique']
                        ],
                        //IK分词器+英文转小写+将ASCII码不在ASCII表前127内的字母、数字和Unicode符号转换为ASCII等效字符
                        'ik_smart_analyzer' => [
                            'tokenizer' => 'ik_smart',//ik_smart-粗粒度分词
                            'filter' => ['lowercase', 'asciifolding']
                        ],
                    ],
                    //配置分词过滤器
                    'filter' => [
                        'my_pinyin' => [
                            'type' => 'pinyin',
                            'keep_separate_first_letter' => false,
                            'keep_full_pinyin' => true,
                            'keep_original' => true,
                            'limit_first_letter_length' => 16,
                            'lowercase' => true,
                            'remove_duplicated_term' => true
                        ],
                        'icfilter' => [
                            'type' => 'ngram',
                            'min_gram' => 1,
                            'max_gram' => 128
                        ]
                    ],
                ]
            ],
            'mappings' => [
                '_doc' => [
                    'dynamic' => false,
                    'properties' => [
                        'content' => [
                            'type' => 'text',
                            'analyzer' => 'ik_max_word_analyzer',
                            'search_analyzer' => 'ik_smart_analyzer',
                        ],
                        'brand' => [
                            'type' => 'keyword',
                            'copy_to' => ['content']
                        ],
                        'model' => [
                            'type' => 'keyword',
                            'copy_to' => ['content']
                        ],
                        'spec' => [
                            'type' => 'keyword',
                            'copy_to' => ['content']
                        ],
                        'created_at' => [
                            'type' => 'date',
                            'format' => 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis',
                        ],
                    ],
                ]
            ],
        ]
    ]);
}

//...可以开始开发了
```

> 场景二：
>
> 由于场景一种mappings下面的字段需要增加updated\_at，这时可以使用版本进行更新
>
> 这是，我们使用新的索引wares\_v4，并设置一个别名wares，然后把old\_index设置为原本的索引名称wares\_v3，意思是把V3的数据复制到V4去，V3的数据不用保留的话就把is\_delete\_old设置为true

```
$config = [
    'host' => ['192.168.0.52:9200'],//es地址
    'index' => 'wares_v4',          //索引名称
    'alias' => 'wares',             //别名
    'old_host' => '',               //需要迁移的地址，默认为空，该字段暂不支持
    'old_index' => 'wares_v3',      //要迁移的索引，如果和index不同，则会把该索引下面的数据复制到index下
    'is_delete_old' => true,        //是否删除旧版索引，如果为true，则复制到index后，会删除old_index的内容
];
```

> 然后通过 autoVersionManagement 方法自动管理版本库

```
$es->autoVersionManagement($config,[
    'body' => [
        'settings' => [
            'analysis' => [
                //配置分析器
                'analyzer' => [
                    //IK分词器+拼音分词过滤器+内置ngram分词过滤器
                    'ik_max_word_analyzer' => [
                        'tokenizer' => 'ik_max_word',//ik_max_word-细粒度分词
                        'filter' => ['icfilter', 'my_pinyin', 'unique']
                    ],
                    //IK分词器+英文转小写+将ASCII码不在ASCII表前127内的字母、数字和Unicode符号转换为ASCII等效字符
                    'ik_smart_analyzer' => [
                        'tokenizer' => 'ik_smart',//ik_smart-粗粒度分词
                        'filter' => ['lowercase', 'asciifolding']
                    ],
                ],
                //配置分词过滤器
                'filter' => [
                    'my_pinyin' => [
                        'type' => 'pinyin',
                        'keep_separate_first_letter' => false,
                        'keep_full_pinyin' => true,
                        'keep_original' => true,
                        'limit_first_letter_length' => 16,
                        'lowercase' => true,
                        'remove_duplicated_term' => true
                    ],
                    'icfilter' => [
                        'type' => 'ngram',
                        'min_gram' => 1,
                        'max_gram' => 128
                    ]
                ],
            ]
        ],
        'mappings' => [
            '_doc' => [
                'dynamic' => false,
                'properties' => [
                    'content' => [
                        'type' => 'text',
                        'analyzer' => 'ik_max_word_analyzer',
                        'search_analyzer' => 'ik_smart_analyzer',
                    ],
                    'brand' => [
                        'type' => 'keyword',
                        'copy_to' => ['content']
                    ],
                    'model' => [
                        'type' => 'keyword',
                        'copy_to' => ['content']
                    ],
                    'spec' => [
                        'type' => 'keyword',
                        'copy_to' => ['content']
                    ],
                    'created_at' => [
                        'type' => 'date',
                        'format' => 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis',
                    ],
                    'updated_at' => [
                        'type' => 'date',
                        'format' => 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis',
                    ],
                ],
            ]
        ],
    ]
])
```

> 如果后续再有修改，只需要修改配置config，把index加一个版本 wares\_v5，old\_index=wares\_v4，就可以了

```
$config = [
    'host' => ['192.168.0.52:9200'],//es地址
    'index' => 'wares_v5',          //索引名称
    'alias' => 'wares',             //别名
    'old_host' => '',               //需要迁移的地址，默认为空，该字段暂不支持
    'old_index' => 'wares_v4',      //要迁移的索引，如果和index不同，则会把该索引下面的数据复制到index下
    'is_delete_old' => true,        //是否删除旧版索引，如果为true，则复制到index后，会删除old_index的内容
];
$es->autoVersionManagement($config,[
    'body' => [
        'settings' => [
            'analysis' => [
                //配置分析器
                'analyzer' => [
                    //IK分词器+拼音分词过滤器+内置ngram分词过滤器
                    'ik_max_word_analyzer' => [
                        'tokenizer' => 'ik_max_word',//ik_max_word-细粒度分词
                        'filter' => ['icfilter', 'my_pinyin', 'unique']
                    ],
                    //IK分词器+英文转小写+将ASCII码不在ASCII表前127内的字母、数字和Unicode符号转换为ASCII等效字符
                    'ik_smart_analyzer' => [
                        'tokenizer' => 'ik_smart',//ik_smart-粗粒度分词
                        'filter' => ['lowercase', 'asciifolding']
                    ],
                ],
                //配置分词过滤器
                'filter' => [
                    'my_pinyin' => [
                        'type' => 'pinyin',
                        'keep_separate_first_letter' => false,
                        'keep_full_pinyin' => true,
                        'keep_original' => true,
                        'limit_first_letter_length' => 16,
                        'lowercase' => true,
                        'remove_duplicated_term' => true
                    ],
                    'icfilter' => [
                        'type' => 'ngram',
                        'min_gram' => 1,
                        'max_gram' => 128
                    ]
                ],
            ]
        ],
        'mappings' => [
            '_doc' => [
                'dynamic' => false,
                'properties' => [
                    'content' => [
                        'type' => 'text',
                        'analyzer' => 'ik_max_word_analyzer',
                        'search_analyzer' => 'ik_smart_analyzer',
                    ],
                    'brand' => [
                        'type' => 'keyword',
                        'copy_to' => ['content']
                    ],
                    'model' => [
                        'type' => 'keyword',
                        'copy_to' => ['content']
                    ],
                    'spec' => [
                        'type' => 'keyword',
                        'copy_to' => ['content']
                    ],
                    'updated_at' => [
                        'type' => 'date',
                        'format' => 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis',
                    ],
                ],
            ]
        ],
    ]
])
```

> 这一次我去掉了created\_at字段

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~74 days

Total

3

Last Release

1270d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8802f0e7f34553ef9ae20f6be11705fcca46e90b94a76000e3fec292fc1d8dae?d=identicon)[ChinaXander](/maintainers/ChinaXander)

### Embed Badge

![Health badge](/badges/xander-php-es/health.svg)

```
[![Health](https://phpackages.com/badges/xander-php-es/health.svg)](https://phpackages.com/packages/xander-php-es)
```

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

26.2k161.6k7](/packages/bagisto-bagisto)[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[unopim/unopim

UnoPim Laravel PIM

9.4k1.8k](/packages/unopim-unopim)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
