1
|
|
|
<?php namespace Nord\Lumen\Elasticsearch; |
2
|
|
|
|
3
|
|
|
use Elasticsearch\Client; |
4
|
|
|
use Nord\Lumen\Elasticsearch\Contracts\ElasticsearchServiceContract; |
5
|
|
|
use Nord\Lumen\Elasticsearch\Parsers\SortStringParser; |
6
|
|
|
use Nord\Lumen\Elasticsearch\Search\Aggregation\AggregationBuilder; |
7
|
|
|
use Nord\Lumen\Elasticsearch\Search\Query\QueryBuilder; |
8
|
|
|
use Nord\Lumen\Elasticsearch\Search\Search; |
9
|
|
|
use Nord\Lumen\Elasticsearch\Search\Sort; |
10
|
|
|
|
11
|
|
|
class ElasticsearchService implements ElasticsearchServiceContract |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var Client |
16
|
|
|
*/ |
17
|
|
|
private $client; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* ElasticsearchService constructor. |
22
|
|
|
* |
23
|
|
|
* @param Client $client |
24
|
|
|
*/ |
25
|
|
|
public function __construct(Client $client) |
26
|
|
|
{ |
27
|
|
|
$this->client = $client; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @inheritdoc |
33
|
|
|
*/ |
34
|
|
|
public function search(array $params = []) |
35
|
|
|
{ |
36
|
|
|
return $this->client->search($params); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
|
|
public function index(array $params = []) |
44
|
|
|
{ |
45
|
|
|
return $this->client->index($params); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritdoc |
51
|
|
|
*/ |
52
|
|
|
public function reindex(array $params = []) |
53
|
|
|
{ |
54
|
|
|
return $this->client->reindex($params); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
|
|
public function updateByQuery(array $params = []) |
62
|
|
|
{ |
63
|
|
|
return $this->client->updateByQuery($params); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritdoc |
69
|
|
|
*/ |
70
|
|
|
public function bulk(array $params = []) |
71
|
|
|
{ |
72
|
|
|
return $this->client->bulk($params); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
|
|
public function delete(array $params = []) |
80
|
|
|
{ |
81
|
|
|
return $this->client->delete($params); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @inheritdoc |
87
|
|
|
*/ |
88
|
|
|
public function deleteByQuery(array $params = []) |
89
|
|
|
{ |
90
|
|
|
return $this->client->deleteByQuery($params); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @inheritdoc |
96
|
|
|
*/ |
97
|
|
|
public function tasks() |
98
|
|
|
{ |
99
|
|
|
return $this->client->tasks(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @inheritdoc |
105
|
|
|
*/ |
106
|
|
|
public function create(array $params = []) |
107
|
|
|
{ |
108
|
|
|
return $this->client->create($params); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @inheritdoc |
114
|
|
|
*/ |
115
|
|
|
public function exists(array $params = []) |
116
|
|
|
{ |
117
|
|
|
return $this->client->exists($params); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @inheritdoc |
123
|
|
|
*/ |
124
|
|
|
public function indices() |
125
|
|
|
{ |
126
|
|
|
return $this->client->indices(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @inheritdoc |
132
|
|
|
*/ |
133
|
|
|
public function createSearch() |
134
|
|
|
{ |
135
|
|
|
return new Search(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @inheritdoc |
141
|
|
|
*/ |
142
|
|
|
public function createSort() |
143
|
|
|
{ |
144
|
|
|
return new Sort(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @inheritdoc |
150
|
|
|
*/ |
151
|
|
|
public function createQueryBuilder() |
152
|
|
|
{ |
153
|
|
|
return new QueryBuilder(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @inheritdoc |
159
|
|
|
*/ |
160
|
|
|
public function createSortBuilder() |
161
|
|
|
{ |
162
|
|
|
return new Sort\SortBuilder(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @inheritdoc |
168
|
|
|
*/ |
169
|
|
|
public function createSortStringParser(array $config = []) |
170
|
|
|
{ |
171
|
|
|
return new SortStringParser($config); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @inheritdoc |
177
|
|
|
*/ |
178
|
|
|
public function createAggregationBuilder() |
179
|
|
|
{ |
180
|
|
|
return new AggregationBuilder(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @inheritdoc |
186
|
|
|
*/ |
187
|
|
|
public function execute(Search $search) |
188
|
|
|
{ |
189
|
|
|
return $this->search([ |
190
|
|
|
'index' => $search->getIndex(), |
191
|
|
|
'type' => $search->getType(), |
192
|
|
|
'body' => $search->buildBody(), |
193
|
|
|
]); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|