Downloads
Stars
Version
Composer 下载
composer require yeoman_j/elastic-tool
Add elasticsearch/elasticsearch
{
"require": {
"elasticsearch/elasticsearch": "^6.7"
}
}
[
'elasticsearch' => [
//---elasticsearch 服务地址
'hosts' => [
env('ELASTICSEARCH_HOST', 'http://localhost'),
],
//---分词
'analyzer' => env('ELASTICSEARCH_ANALYZER', 'ik_max_word'),
'settings' => [],
'filter' => [
'+',
'-',
'&',
'|',
'!',
'(',
')',
'{',
'}',
'[',
']',
'^',
'\\',
'"',
'~',
'*',
'?',
':'
]
],
//--开启搜索日志
'search_log' => 0
];
1.match()
2.offset()
3.mustShould()
$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()
5.shouldWhere()
6.isMust()
7.isNot()
8._source()
9.between()
['price'=>[['>=',10],['<',12]]];
10.distinct()
11.getOneByEs()
12.setShouldCustomizeParams()
13.sort()
14.sortMath()
15.groupBy()
$index = 'a_index';
//---简单搜索 eg:
ElasticTool::operationSearch($index)
->offset(1, 1)
->isFuzzy()
->match(['title' => '欧莱雅'])
->getSearchList();
//---多条件复杂搜索 eg:
ElasticTool::operationSearch('fx_test_goods_index_v1')
->offset(1, 1)
->match(['title' => '欧莱雅'])
->shouldWhere(['search' => [
'match' => ['keyword' => '测试', 'keyword2' => '测试2' ]]])
->isFuzzy()
->mustShould(['search' => ['match' => ['seo_word' => '测试']]])
->query('测试2', ['title_q'])
->isMust([
'status' => 1,
'type' =>
[1, 3, 4, 6]
])
->shouldWhere(['filter' => ['status' => 2]])
->getSearchList();
##索引创建 删除...
ElasticTool::operationIndex();
$index = 'a_index';
$data = [
1=>[
'title'=>'test',
'keyword'=>'test',
'id'=>2
],
2=>[
'title'=>'test',
'keyword'=>'test'
],
];
ElasticTool::operationDesc($index)->addAll($data);
$index = 'a_index';
$id = 1;
$data = ['a'=>1];
ElasticTool::operationDesc($index)->update($data,$id);