Download the PHP package archerzdip/hyperf-elasticsearch without Composer
On this page you can find all versions of the php package archerzdip/hyperf-elasticsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download archerzdip/hyperf-elasticsearch
More information about archerzdip/hyperf-elasticsearch
Files in archerzdip/hyperf-elasticsearch
Package hyperf-elasticsearch
Short Description The Elasticsearch Driver for Hyperf Scout
License MIT
Informations about the package hyperf-elasticsearch
Hyperf Elasticsearch Driver
根据 babenkoivan/scout-elasticsearch-driver 改造的基于Hyperf框架的ElasticSearch组件。
Requirements
- PHP version >=7.2.0
- Hyperf Framework version >2.0
- Elasticsearch version >=7
Installation
Configuration
发布配置文件
- 配置文件在config/autoload/scout_elastic.php, 配置参数如下: *
Option | Description |
---|---|
driver | 默认defalut |
soft_delete | 是否软删除 |
prefix | 前缀 |
client.host | ElasticSearch client, default localhost:9200 .如果存在密码: user:password@host:port |
max_connections | 最大连接数,默认500 |
indexer | 索引方式,目前支持single 和bulk |
chunk.searchable | 批量处理的搜索块数量 |
chuck.unsearchable | 批量处理的搜索块数量 |
update_mapping | 是否自动更新,默认 true |
document_refresh | This option controls when updated documents appear in the search results. Can be set to 'true', 'false', 'wait_for' or null. More details about this option you can find here. By default set to null. |
Index Configurator
所以配置器类用于设置ElasticSearch的索引,可使用以下方式创建新的索引配置器:
默认目录为App\ElasticIndexConfigurator\MyIndexConfigurator
More about index settings you can find in the index management section of Elasticsearch documentation.
Searchable Model
Usage
Basic search usage example:
If you only need the number of matches for a query, use the count
method:
If you need to load relations, use the with
method:
In addition to standard functionality the package offers you the possibility to filter data in Elasticsearch without specifying a query string:
Also you can override model search rules:
And use variety of where
conditions:
And filter out results with a score less than min_score:
And add more complex sorting (geo_distance eg.)
At last, if you want to send a custom request, you can use the searchRaw
method:
This query will return raw response.
Console Commands
Command | Arguments | Description |
---|---|---|
make:index-configurator | name - The name of the class |
Creates a new Elasticsearch index configurator. |
make:searchable-model | name - The name of the class |
Creates a new searchable model. |
make:search-rule | name - The name of the class |
Creates a new search rule. |
elastic:create-index | index-configurator - The index configurator class |
Creates an Elasticsearch index. |
elastic:update-index | index-configurator - The index configurator class |
Updates settings and mappings of an Elasticsearch index. |
elastic:drop-index | index-configurator - The index configurator class |
Drops an Elasticsearch index. |
elastic:update-mapping | model - The model class |
Updates a model mapping. |
elastic:migrate-model | model - The model class, target-index - The index name to migrate |
Migrates model to another index. |
For detailed description and all available options run php bin/hyperf.php help [command]
in the command line.
Search rules
默认目录为App\ElasticSearchRule\MySearchRule
License
MIT