PHPackages                             yeoman\_j/elastic-tool - 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. [Search &amp; Filtering](/categories/search)
4. /
5. yeoman\_j/elastic-tool

ActiveElastic-extensions[Search &amp; Filtering](/categories/search)

yeoman\_j/elastic-tool
======================

Chain tool for operating and implementing elasticsearch

46PHP

Since Sep 7Pushed 5y agoCompare

[ Source](https://github.com/jiniyingming/ElasticSearchTool)[ Packagist](https://packagist.org/packages/yeoman_j/elastic-tool)[ RSS](/packages/yeoman-j-elastic-tool/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

ElasticSearchTool 使用方法
======================

[](#elasticsearchtool-使用方法)

Composer 下载

```
composer require yeoman_j/elastic-tool

```

-

composer.json
-------------

[](#composerjson)

Add elasticsearch/elasticsearch

```
{
    "require": {
        "elasticsearch/elasticsearch": "^6.7"
    }
}
```

Config 配置
---------

[](#config-配置)

```
 [
 	'elasticsearch' => [
 		//---elasticsearch 服务地址
 		'hosts' => [
 			env('ELASTICSEARCH_HOST', 'http://localhost'),
 		],
 		 //---分词
 		'analyzer' => env('ELASTICSEARCH_ANALYZER', 'ik_max_word'),
 		'settings' => [],
 		'filter' => [
 			'+',
 			'-',
 			'&',
 			'|',
 			'!',
 			'(',
 			')',
 			'{',
 			'}',
 			'[',
 			']',
 			'^',
 			'\\',
 			'"',
 			'~',
 			'*',
 			'?',
 			':'
 		]
 	],
 	//--开启搜索日志
 	'search_log' => 0
 ];
```

使用教程
----

[](#使用教程)

搜索功能模块方法介绍
----------

[](#搜索功能模块方法介绍)

1.match()

- 传入值为 array 可多条件
- 分词搜索/全匹配搜索
- 默认为全匹配搜索
- 可配合 isFuzzy(bool) 传入bool值决定搜索方式 true 分词搜索

2.offset()

- 数据分页 所需两个参数 （int 页码,int 每页数量）

3.mustShould()

- 设置或条件 多个或条件 中必须有一项符合
- 可同时设置搜索和筛选功能
- 数据结构 eg:

```
       $whereArray = [
            'search'=>[
                        'match'=>[
                            'search_key'=>'search_word'||[search_word,boost], ...
                            ],
                        'match_phrase'=>[
                            'search_key'=>'search_word'||[search_word,boost],...
                    ],
            'filter'=>['filter_key'=>'(int||string||array)filter_value',...]
       ];
```

4.query()

- 分词搜索 单个搜索词对多个字段进行搜索
- 参数类型为 （string,array）

5.shouldWhere()

- 或条件 非必须
- 参数结构 同 3

6.isMust()

- 必须符合条件 不含搜索
- 筛选类型 为 int string array
- 参数结构 array

7.isNot()

- 必须不符合条件
- 参数类型 同 6

8.\_source()

- 设置返回字段
- 参数类型 array

9.between()

- 区间筛选
- 参数格式

```
['price'=>[['>=',10],['
