line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::ElasticSearch::Bag; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
9
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.0202'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
624
|
use Catmandu::Hits; |
|
1
|
|
|
|
|
23412
|
|
|
1
|
|
|
|
|
41
|
|
8
|
1
|
|
|
1
|
|
11
|
use Cpanel::JSON::XS qw(encode_json decode_json); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
9
|
1
|
|
|
1
|
|
542
|
use Catmandu::Store::ElasticSearch::Searcher; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
36
|
|
10
|
1
|
|
|
1
|
|
509
|
use Catmandu::Store::ElasticSearch::CQL; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
11
|
1
|
|
|
1
|
|
8
|
use Catmandu::Util qw(is_code_ref is_string); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
12
|
1
|
|
|
1
|
|
6
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
13
|
1
|
|
|
1
|
|
368
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with 'Catmandu::Bag'; |
16
|
|
|
|
|
|
|
with 'Catmandu::Droppable'; |
17
|
|
|
|
|
|
|
with 'Catmandu::Flushable'; |
18
|
|
|
|
|
|
|
with 'Catmandu::CQLSearchable'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has index => (is => 'lazy'); |
21
|
|
|
|
|
|
|
has settings => (is => 'lazy'); |
22
|
|
|
|
|
|
|
has mapping => (is => 'lazy'); |
23
|
|
|
|
|
|
|
has type => (is => 'lazy'); |
24
|
|
|
|
|
|
|
has buffer_size => (is => 'lazy', builder => 'default_buffer_size'); |
25
|
|
|
|
|
|
|
has _bulk => (is => 'lazy'); |
26
|
|
|
|
|
|
|
has cql_mapping => (is => 'ro'); |
27
|
|
|
|
|
|
|
has on_error => (is => 'lazy'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub BUILD { |
30
|
0
|
|
|
0
|
0
|
|
$_[0]->create_index; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub create_index { |
34
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
35
|
0
|
|
|
|
|
|
my $es = $self->store->es; |
36
|
0
|
0
|
|
|
|
|
unless ($es->indices->exists(index => $self->index)) { |
37
|
0
|
|
|
|
|
|
$es->indices->create( |
38
|
|
|
|
|
|
|
index => $self->index, |
39
|
|
|
|
|
|
|
body => { |
40
|
|
|
|
|
|
|
settings => $self->settings, |
41
|
|
|
|
|
|
|
mappings => {$self->type => $self->mapping}, |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
0
|
|
sub default_buffer_size {100} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _coerce_on_error { |
51
|
0
|
|
|
0
|
|
|
my ($self, $cb) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if (is_code_ref($cb)) { |
54
|
0
|
|
|
|
|
|
return $cb; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
0
|
0
|
|
|
|
if (is_string($cb) && $cb eq 'throw') { |
57
|
|
|
|
|
|
|
return sub { |
58
|
0
|
|
|
0
|
|
|
my ($action, $res, $i) = @_; |
59
|
0
|
|
|
|
|
|
Catmandu::Error->throw(encode_json($res)); |
60
|
0
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
0
|
0
|
|
|
|
if (is_string($cb) && $cb eq 'log') { |
63
|
|
|
|
|
|
|
return sub { |
64
|
0
|
|
|
0
|
|
|
my ($action, $res, $i) = @_; |
65
|
0
|
|
|
|
|
|
$self->log->error(encode_json($res)); |
66
|
0
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
0
|
0
|
|
|
|
if (is_string($cb) && $cb eq 'ignore') { |
69
|
0
|
|
|
0
|
|
|
return sub { }; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Catmandu::BadArg->throw( |
73
|
0
|
|
|
|
|
|
"on_error should be code ref, 'throw', 'log', or 'ignore'"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _build_on_error { |
77
|
0
|
|
|
0
|
|
|
'log'; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _build_settings { |
81
|
0
|
|
|
0
|
|
|
+{}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _build_mapping { |
85
|
0
|
|
|
0
|
|
|
+{}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _build_index { |
89
|
0
|
|
|
0
|
|
|
$_[0]->name; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _build_type { |
93
|
0
|
|
|
0
|
|
|
$_[0]->name; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _build__bulk { |
97
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
98
|
0
|
|
|
|
|
|
my $on_error = $self->_coerce_on_error($self->on_error); |
99
|
0
|
|
|
|
|
|
my %args = ( |
100
|
|
|
|
|
|
|
index => $self->index, |
101
|
|
|
|
|
|
|
type => $self->type, |
102
|
|
|
|
|
|
|
max_count => $self->buffer_size, |
103
|
|
|
|
|
|
|
on_error => $on_error, |
104
|
|
|
|
|
|
|
); |
105
|
0
|
0
|
|
|
|
|
if ($self->log->is_debug) { |
106
|
|
|
|
|
|
|
$args{on_success} = sub { |
107
|
0
|
|
|
0
|
|
|
my ($action, $res, $i) = @_; |
108
|
0
|
|
|
|
|
|
$self->log->debug(encode_json($res)); |
109
|
0
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
|
$self->store->es->bulk_helper(%args); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub generator { |
115
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
116
|
0
|
|
|
|
|
|
my $id_key = $self->id_key; |
117
|
|
|
|
|
|
|
sub { |
118
|
0
|
|
|
0
|
|
|
state $scroll = do { |
119
|
0
|
|
|
|
|
|
my %args = ( |
120
|
|
|
|
|
|
|
index => $self->index, |
121
|
|
|
|
|
|
|
size => $self->buffer_size, # TODO divide by number of shards |
122
|
|
|
|
|
|
|
body => {query => {match_all => {}},}, |
123
|
|
|
|
|
|
|
); |
124
|
0
|
0
|
|
|
|
|
if ($self->store->is_es_1_or_2) { |
125
|
0
|
|
|
|
|
|
$args{search_type} = 'scan'; |
126
|
0
|
|
|
|
|
|
$args{type} = $self->type; |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
|
$self->store->es->scroll_helper(%args); |
129
|
|
|
|
|
|
|
}; |
130
|
0
|
|
0
|
|
|
|
my $doc = $scroll->next // do { |
131
|
0
|
|
|
|
|
|
$scroll->finish; |
132
|
0
|
|
|
|
|
|
return; |
133
|
|
|
|
|
|
|
}; |
134
|
0
|
|
|
|
|
|
my $data = $doc->{_source}; |
135
|
0
|
|
|
|
|
|
$data->{$id_key} = $doc->{_id}; |
136
|
0
|
|
|
|
|
|
$data; |
137
|
0
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub count { |
141
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
142
|
0
|
|
|
|
|
|
my $store = $self->store; |
143
|
0
|
|
|
|
|
|
my %args = (index => $self->index,); |
144
|
0
|
0
|
|
|
|
|
if ($store->is_es_1_or_2) { |
145
|
0
|
|
|
|
|
|
$args{type} = $self->type; |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
$store->es->count(%args)->{count}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub get { |
151
|
|
|
|
|
|
|
my ($self, $id) = @_; |
152
|
|
|
|
|
|
|
try { |
153
|
|
|
|
|
|
|
my $data = $self->store->es->get_source( |
154
|
|
|
|
|
|
|
index => $self->index, |
155
|
|
|
|
|
|
|
type => $self->type, |
156
|
|
|
|
|
|
|
id => $id, |
157
|
|
|
|
|
|
|
); |
158
|
|
|
|
|
|
|
$data->{$self->id_key} = $id; |
159
|
|
|
|
|
|
|
$data; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
catch_case ['Search::Elasticsearch::Error::Missing' => sub {undef}]; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub add { |
165
|
|
|
|
|
|
|
my ($self, $data) = @_; |
166
|
|
|
|
|
|
|
$data = {%$data}; |
167
|
|
|
|
|
|
|
my $id = delete($data->{$self->id_key}); |
168
|
|
|
|
|
|
|
$self->_bulk->index({id => $id, source => $data,}); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub delete { |
172
|
|
|
|
|
|
|
my ($self, $id) = @_; |
173
|
|
|
|
|
|
|
$self->_bulk->delete({id => $id}); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub delete_all { |
177
|
|
|
|
|
|
|
my ($self) = @_; |
178
|
|
|
|
|
|
|
my $es = $self->store->es; |
179
|
|
|
|
|
|
|
if ($es->can('delete_by_query')) { |
180
|
|
|
|
|
|
|
$es->delete_by_query( |
181
|
|
|
|
|
|
|
index => $self->index, |
182
|
|
|
|
|
|
|
type => $self->type, |
183
|
|
|
|
|
|
|
body => {query => {match_all => {}},}, |
184
|
|
|
|
|
|
|
); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
else { # TODO document plugin needed for es 2.x |
187
|
|
|
|
|
|
|
$es->transport->perform_request( |
188
|
|
|
|
|
|
|
method => 'DELETE', |
189
|
|
|
|
|
|
|
path => '/' . $self->index . '/' . $self->type . '/_query', |
190
|
|
|
|
|
|
|
body => {query => {match_all => {}},} |
191
|
|
|
|
|
|
|
); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub delete_by_query { |
196
|
|
|
|
|
|
|
my ($self, %args) = @_; |
197
|
|
|
|
|
|
|
my $es = $self->store->es; |
198
|
|
|
|
|
|
|
if ($es->can('delete_by_query')) { |
199
|
|
|
|
|
|
|
$es->delete_by_query( |
200
|
|
|
|
|
|
|
index => $self->index, |
201
|
|
|
|
|
|
|
type => $self->type, |
202
|
|
|
|
|
|
|
body => {query => $args{query},}, |
203
|
|
|
|
|
|
|
); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
else { # TODO document plugin needed for es 2.x |
206
|
|
|
|
|
|
|
$es->transport->perform_request( |
207
|
|
|
|
|
|
|
method => 'DELETE', |
208
|
|
|
|
|
|
|
path => '/' . $self->index . '/' . $self->type . '/_query', |
209
|
|
|
|
|
|
|
body => {query => $args{query},} |
210
|
|
|
|
|
|
|
); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub flush { |
215
|
0
|
|
|
0
|
0
|
|
$_[0]->_bulk->flush; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub commit { |
219
|
|
|
|
|
|
|
my ($self) = @_; |
220
|
|
|
|
|
|
|
$self->store->es->transport->perform_request( |
221
|
|
|
|
|
|
|
method => 'POST', |
222
|
|
|
|
|
|
|
path => '/' . $self->index . '/_refresh', |
223
|
|
|
|
|
|
|
); |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub search { |
227
|
|
|
|
|
|
|
my ($self, %args) = @_; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
my $id_key = $self->id_key; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
my $start = delete $args{start}; |
232
|
|
|
|
|
|
|
my $limit = delete $args{limit}; |
233
|
|
|
|
|
|
|
my $scroll_id = delete $args{scroll_id}; |
234
|
|
|
|
|
|
|
my $scroll = delete $args{scroll}; |
235
|
|
|
|
|
|
|
my $bag = delete $args{reify}; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
my $res; |
238
|
|
|
|
|
|
|
if (defined $scroll_id) { |
239
|
|
|
|
|
|
|
my %es_args = (body => {scroll_id => $scroll_id},); |
240
|
|
|
|
|
|
|
if (defined $scroll) { |
241
|
|
|
|
|
|
|
$es_args{scroll} = $scroll; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
$res = $self->store->es->scroll(%es_args); |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
else { |
246
|
|
|
|
|
|
|
my %es_args |
247
|
|
|
|
|
|
|
= (index => $self->index, body => {%args, size => $limit,},); |
248
|
|
|
|
|
|
|
if ($self->store->is_es_1_or_2) { |
249
|
|
|
|
|
|
|
$es_args{type} = $self->type; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
if ($bag) { |
252
|
|
|
|
|
|
|
$es_args{body}{fields} = []; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
if (defined $scroll) { |
255
|
|
|
|
|
|
|
$es_args{scroll} = $scroll; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
else { |
258
|
|
|
|
|
|
|
$es_args{body}{from} = $start; |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
$res = $self->store->es->search(%es_args); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
my $docs = $res->{hits}{hits}; |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
my $hits |
266
|
|
|
|
|
|
|
= {start => $start, limit => $limit, total => $res->{hits}{total},}; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
if ($bag) { |
269
|
|
|
|
|
|
|
$hits->{hits} = [map {$bag->get($_->{_id})} @$docs]; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
elsif ($args{fields}) { |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
# TODO check if fields includes id_key |
274
|
|
|
|
|
|
|
$hits->{hits} = [map {$_->{fields} || +{}} @$docs]; |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
else { |
277
|
|
|
|
|
|
|
$hits->{hits} = [ |
278
|
|
|
|
|
|
|
map { |
279
|
|
|
|
|
|
|
my $data = $_->{_source}; |
280
|
|
|
|
|
|
|
$data->{$id_key} = $_->{_id}; |
281
|
|
|
|
|
|
|
$data; |
282
|
|
|
|
|
|
|
} @$docs |
283
|
|
|
|
|
|
|
]; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
$hits = Catmandu::Hits->new($hits); |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
$hits->{scroll_id} = $res->{_scroll_id} if exists $res->{_scroll_id}; |
289
|
|
|
|
|
|
|
for my $key (qw(facets suggest aggregations)) { |
290
|
|
|
|
|
|
|
$hits->{$key} = $res->{$key} if exists $res->{$key}; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
if ($args{highlight}) { |
294
|
|
|
|
|
|
|
for my $hit (@$docs) { |
295
|
|
|
|
|
|
|
if (my $hl = $hit->{highlight}) { |
296
|
|
|
|
|
|
|
$hits->{highlight}{$hit->{$id_key}} = $hl; |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
$hits; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
sub searcher { |
305
|
|
|
|
|
|
|
my ($self, %args) = @_; |
306
|
|
|
|
|
|
|
Catmandu::Store::ElasticSearch::Searcher->new(%args, bag => $self); |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
sub translate_sru_sortkeys { |
310
|
0
|
|
|
0
|
0
|
|
my ($self, $sortkeys) = @_; |
311
|
|
|
|
|
|
|
[ |
312
|
0
|
|
|
|
|
|
grep {defined $_} map {$self->_translate_sru_sortkey($_)} split /\s+/, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
$sortkeys |
314
|
|
|
|
|
|
|
]; |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub _translate_sru_sortkey { |
318
|
0
|
|
|
0
|
|
|
my ($self, $sortkey) = @_; |
319
|
0
|
|
|
|
|
|
my ($field, $schema, $asc) = split /,/, $sortkey; |
320
|
0
|
0
|
|
|
|
|
$field || return; |
321
|
0
|
0
|
|
|
|
|
if (my $map = $self->cql_mapping) { |
322
|
0
|
|
|
|
|
|
$field = lc $field; |
323
|
|
|
|
|
|
|
$field =~ s/(?<=[^_])_(?=[^_])//g |
324
|
0
|
0
|
|
|
|
|
if $map->{strip_separating_underscores}; |
325
|
0
|
|
0
|
|
|
|
$map = $map->{indexes} || return; |
326
|
0
|
|
0
|
|
|
|
$map = $map->{$field} || return; |
327
|
0
|
0
|
|
|
|
|
$map->{sort} || return; |
328
|
0
|
0
|
0
|
|
|
|
if (ref $map->{sort} && $map->{sort}{field}) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
329
|
0
|
|
|
|
|
|
$field = $map->{sort}{field}; |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
elsif (ref $map->{field}) { |
332
|
0
|
|
|
|
|
|
$field = $map->{field}->[0]; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
elsif ($map->{field}) { |
335
|
0
|
|
|
|
|
|
$field = $map->{field}; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
} |
338
|
0
|
|
0
|
|
|
|
$asc //= 1; |
339
|
0
|
0
|
|
|
|
|
+{$field => $asc ? 'asc' : 'desc'}; |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub translate_cql_query { |
343
|
0
|
|
|
0
|
0
|
|
my ($self, $query) = @_; |
344
|
0
|
|
|
|
|
|
Catmandu::Store::ElasticSearch::CQL->new( |
345
|
|
|
|
|
|
|
mapping => $self->cql_mapping, |
346
|
|
|
|
|
|
|
id_key => $self->id_key |
347
|
|
|
|
|
|
|
)->parse($query); |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
sub normalize_query { |
351
|
0
|
|
|
0
|
0
|
|
my ($self, $query) = @_; |
352
|
0
|
0
|
|
|
|
|
if (ref $query) { |
|
|
0
|
|
|
|
|
|
353
|
0
|
|
|
|
|
|
$query; |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
elsif ($query) { |
356
|
0
|
|
|
|
|
|
{query_string => {query => $query}}; |
357
|
|
|
|
|
|
|
} |
358
|
|
|
|
|
|
|
else { |
359
|
0
|
|
|
|
|
|
{match_all => {}}; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
# assume a sort string is JSON encoded |
364
|
|
|
|
|
|
|
sub normalize_sort { |
365
|
0
|
|
|
0
|
0
|
|
my ($self, $sort) = @_; |
366
|
0
|
0
|
|
|
|
|
return $sort if ref $sort; |
367
|
0
|
0
|
|
|
|
|
return if !$sort; |
368
|
0
|
|
|
|
|
|
decode_json($sort); |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
sub drop { |
372
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
373
|
0
|
|
|
|
|
|
$self->store->es->indices->delete(index => $self->index); |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
1; |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
__END__ |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
=pod |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
=head1 NAME |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
Catmandu::Store::ElasticSearch::Bag - Catmandu::Bag implementation for Elasticsearch |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
=head1 DESCRIPTION |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
See the main documentation at L<Catmandu::Store::ElasticSearch>. |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
=head1 METHODS |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
This class inherits all the methods of L<Catmandu::Bag>, |
393
|
|
|
|
|
|
|
L<Catmandu::CQLSearchable> and L<Catmandu::Droppable>. |
394
|
|
|
|
|
|
|
It also provides the following methods: |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
=head2 create_index() |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
This method is called automatically when the bag is instantiated. You only need |
399
|
|
|
|
|
|
|
to call it manually it after deleting the index with C<drop> or the |
400
|
|
|
|
|
|
|
Elasticsearch API. |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
=head1 SEE ALSO |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
L<Catmandu::Bag>, L<Catmandu::Searchable>, L<Catmandu::CQLSearchable>, L<Catmandu::Droppable> |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
=cut |