line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Elasticsearch::Util::API::QS; |
2
|
|
|
|
|
|
|
$Elasticsearch::Util::API::QS::VERSION = '1.05'; |
3
|
42
|
|
|
42
|
|
303
|
use strict; |
|
42
|
|
|
|
|
93
|
|
|
42
|
|
|
|
|
1509
|
|
4
|
42
|
|
|
42
|
|
248
|
use warnings; |
|
42
|
|
|
|
|
93
|
|
|
42
|
|
|
|
|
1503
|
|
5
|
|
|
|
|
|
|
|
6
|
42
|
|
|
42
|
|
238
|
use Sub::Exporter -setup => { exports => ['qs_init'] }; |
|
42
|
|
|
|
|
89
|
|
|
42
|
|
|
|
|
540
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our %Handler = ( |
9
|
|
|
|
|
|
|
string => sub {"$_[0]"}, |
10
|
|
|
|
|
|
|
list => sub { |
11
|
|
|
|
|
|
|
ref $_[0] eq 'ARRAY' |
12
|
|
|
|
|
|
|
? join( ',', @{ shift() } ) |
13
|
|
|
|
|
|
|
: shift(); |
14
|
|
|
|
|
|
|
}, |
15
|
|
|
|
|
|
|
bool => sub { $_[0] ? 1 : 0 }, |
16
|
|
|
|
|
|
|
enum => sub {"$_[0]"}, |
17
|
|
|
|
|
|
|
number => sub { 0 + $_[0] }, |
18
|
|
|
|
|
|
|
datetime => sub {"$_[0]"}, |
19
|
|
|
|
|
|
|
duration => sub {"$_[0]"}, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our %Params = ( |
23
|
|
|
|
|
|
|
all => { type => 'bool' }, |
24
|
|
|
|
|
|
|
allow_no_indices => { type => 'bool' }, |
25
|
|
|
|
|
|
|
analyze_wildcard => { type => 'bool' }, |
26
|
|
|
|
|
|
|
analyzer => { type => 'string' }, |
27
|
|
|
|
|
|
|
boost_terms => { type => 'number' }, |
28
|
|
|
|
|
|
|
bytes => { type => 'enum', options => [ 'b', 'k', 'm', 'g' ] }, |
29
|
|
|
|
|
|
|
clear => { type => 'bool' }, |
30
|
|
|
|
|
|
|
completion => { type => 'bool' }, |
31
|
|
|
|
|
|
|
completion_fields => { type => 'list' }, |
32
|
|
|
|
|
|
|
consistency => { |
33
|
|
|
|
|
|
|
options => [ 'one', 'quorum', 'all' ], |
34
|
|
|
|
|
|
|
type => 'enum' |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
default_operator => { |
37
|
|
|
|
|
|
|
default => 'OR', |
38
|
|
|
|
|
|
|
options => [ 'AND', 'OR' ], |
39
|
|
|
|
|
|
|
type => 'enum' |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
delay => { type => 'duration' }, |
42
|
|
|
|
|
|
|
df => { type => 'string' }, |
43
|
|
|
|
|
|
|
docs => { type => 'bool' }, |
44
|
|
|
|
|
|
|
dry_run => { type => 'bool' }, |
45
|
|
|
|
|
|
|
exit => { type => 'bool' }, |
46
|
|
|
|
|
|
|
expand_wildcards => { type => 'enum', options => [ 'open', 'closed' ] }, |
47
|
|
|
|
|
|
|
explain => { type => 'bool' }, |
48
|
|
|
|
|
|
|
field => { type => 'string' }, |
49
|
|
|
|
|
|
|
field_statistics => { type => 'bool' }, |
50
|
|
|
|
|
|
|
fielddata => { type => 'bool' }, |
51
|
|
|
|
|
|
|
fielddata_fields => { type => 'list' }, |
52
|
|
|
|
|
|
|
fields => { type => 'list' }, |
53
|
|
|
|
|
|
|
filter => { type => 'bool' }, |
54
|
|
|
|
|
|
|
filter_blocks => { type => 'bool' }, |
55
|
|
|
|
|
|
|
filter_cache => { type => 'bool' }, |
56
|
|
|
|
|
|
|
filter_index_templates => { type => 'bool' }, |
57
|
|
|
|
|
|
|
filter_indices => { type => 'list' }, |
58
|
|
|
|
|
|
|
filter_keys => { type => 'bool' }, |
59
|
|
|
|
|
|
|
filter_metadata => { type => 'bool' }, |
60
|
|
|
|
|
|
|
filter_nodes => { type => 'bool' }, |
61
|
|
|
|
|
|
|
filter_routing_table => { type => 'bool' }, |
62
|
|
|
|
|
|
|
filters => { type => 'list' }, |
63
|
|
|
|
|
|
|
flat_settings => { type => 'bool' }, |
64
|
|
|
|
|
|
|
flush => { type => 'bool' }, |
65
|
|
|
|
|
|
|
force => { type => 'bool' }, |
66
|
|
|
|
|
|
|
format => { |
67
|
|
|
|
|
|
|
default => 'detailed', |
68
|
|
|
|
|
|
|
options => [ 'detailed', 'text' ], |
69
|
|
|
|
|
|
|
type => 'enum' |
70
|
|
|
|
|
|
|
}, |
71
|
|
|
|
|
|
|
from => { type => 'number' }, |
72
|
|
|
|
|
|
|
fs => { type => 'bool' }, |
73
|
|
|
|
|
|
|
full => { type => 'bool' }, |
74
|
|
|
|
|
|
|
full_id => { type => 'bool' }, |
75
|
|
|
|
|
|
|
get => { type => 'bool' }, |
76
|
|
|
|
|
|
|
groups => { type => 'list' }, |
77
|
|
|
|
|
|
|
http => { type => 'bool' }, |
78
|
|
|
|
|
|
|
h => { type => 'list' }, |
79
|
|
|
|
|
|
|
help => { type => 'bool' }, |
80
|
|
|
|
|
|
|
human => { type => 'bool' }, |
81
|
|
|
|
|
|
|
id => { type => 'string' }, |
82
|
|
|
|
|
|
|
id_cache => { type => 'bool' }, |
83
|
|
|
|
|
|
|
ids => { type => 'list' }, |
84
|
|
|
|
|
|
|
ignore_conflicts => { type => 'bool' }, |
85
|
|
|
|
|
|
|
ignore_indices => { |
86
|
|
|
|
|
|
|
default => 'none', |
87
|
|
|
|
|
|
|
options => [ 'none', 'missing' ], |
88
|
|
|
|
|
|
|
type => 'enum' |
89
|
|
|
|
|
|
|
}, |
90
|
|
|
|
|
|
|
ignore => { type => 'list', }, |
91
|
|
|
|
|
|
|
ignore_unavailable => { type => 'bool' }, |
92
|
|
|
|
|
|
|
include_defaults => { type => 'bool' }, |
93
|
|
|
|
|
|
|
index => { type => 'list' }, |
94
|
|
|
|
|
|
|
index_templates => { type => 'list' }, |
95
|
|
|
|
|
|
|
indexing => { type => 'bool' }, |
96
|
|
|
|
|
|
|
indices => { type => 'bool' }, |
97
|
|
|
|
|
|
|
indices_boost => { type => 'list' }, |
98
|
|
|
|
|
|
|
interval => { type => 'duration' }, |
99
|
|
|
|
|
|
|
jvm => { type => 'bool' }, |
100
|
|
|
|
|
|
|
lang => { type => 'string' }, |
101
|
|
|
|
|
|
|
lenient => { type => 'bool' }, |
102
|
|
|
|
|
|
|
level => { |
103
|
|
|
|
|
|
|
options => [ 'cluster', 'node', 'indices', 'shards' ], |
104
|
|
|
|
|
|
|
type => 'enum' |
105
|
|
|
|
|
|
|
}, |
106
|
|
|
|
|
|
|
local => { type => 'bool' }, |
107
|
|
|
|
|
|
|
lowercase_expanded_terms => { type => 'bool' }, |
108
|
|
|
|
|
|
|
master_timeout => { type => 'duration' }, |
109
|
|
|
|
|
|
|
max_doc_freq => { type => 'number' }, |
110
|
|
|
|
|
|
|
max_num_segments => { type => 'number' }, |
111
|
|
|
|
|
|
|
max_query_terms => { type => 'number' }, |
112
|
|
|
|
|
|
|
max_word_len => { type => 'number' }, # depr 0.90 |
113
|
|
|
|
|
|
|
max_word_length => { type => 'number' }, |
114
|
|
|
|
|
|
|
merge => { type => 'bool' }, |
115
|
|
|
|
|
|
|
min_doc_freq => { type => 'number' }, |
116
|
|
|
|
|
|
|
min_score => { type => 'number' }, |
117
|
|
|
|
|
|
|
min_term_freq => { type => 'number' }, |
118
|
|
|
|
|
|
|
min_word_len => { type => 'number' }, # depr 0.90 |
119
|
|
|
|
|
|
|
min_word_length => { type => 'number' }, |
120
|
|
|
|
|
|
|
mlt_fields => { type => 'list' }, |
121
|
|
|
|
|
|
|
name => { type => 'list' }, |
122
|
|
|
|
|
|
|
network => { type => 'bool' }, |
123
|
|
|
|
|
|
|
offsets => { type => 'bool' }, |
124
|
|
|
|
|
|
|
only_expunge_deletes => { type => 'bool' }, |
125
|
|
|
|
|
|
|
op_type => { |
126
|
|
|
|
|
|
|
default => 'index', |
127
|
|
|
|
|
|
|
options => [ 'index', 'create' ], |
128
|
|
|
|
|
|
|
type => 'enum' |
129
|
|
|
|
|
|
|
}, |
130
|
|
|
|
|
|
|
order => { type => 'number' }, |
131
|
|
|
|
|
|
|
os => { type => 'bool' }, |
132
|
|
|
|
|
|
|
parent => { type => 'string' }, |
133
|
|
|
|
|
|
|
payloads => { type => 'bool' }, |
134
|
|
|
|
|
|
|
percent_terms_to_match => { type => 'number' }, |
135
|
|
|
|
|
|
|
percolate => { type => 'string' }, |
136
|
|
|
|
|
|
|
percolate_index => { type => 'string' }, |
137
|
|
|
|
|
|
|
percolate_type => { type => 'string' }, |
138
|
|
|
|
|
|
|
plugin => { type => 'bool' }, |
139
|
|
|
|
|
|
|
positions => { type => 'bool' }, |
140
|
|
|
|
|
|
|
prefer_local => { type => 'bool' }, |
141
|
|
|
|
|
|
|
preference => { type => 'string' }, |
142
|
|
|
|
|
|
|
pri => { type => 'bool' }, |
143
|
|
|
|
|
|
|
process => { type => 'bool' }, |
144
|
|
|
|
|
|
|
q => { type => 'string' }, |
145
|
|
|
|
|
|
|
realtime => { type => 'bool' }, |
146
|
|
|
|
|
|
|
recovery => { type => 'bool' }, |
147
|
|
|
|
|
|
|
recycler => { type => 'bool' }, |
148
|
|
|
|
|
|
|
refresh => { type => 'bool' }, |
149
|
|
|
|
|
|
|
replication => { |
150
|
|
|
|
|
|
|
default => 'sync', |
151
|
|
|
|
|
|
|
options => [ 'sync', 'async' ], |
152
|
|
|
|
|
|
|
type => 'enum' |
153
|
|
|
|
|
|
|
}, |
154
|
|
|
|
|
|
|
retry_on_conflict => { type => 'number' }, |
155
|
|
|
|
|
|
|
routing => { type => 'string' }, |
156
|
|
|
|
|
|
|
script => { type => 'string', }, |
157
|
|
|
|
|
|
|
scroll => { type => 'duration' }, |
158
|
|
|
|
|
|
|
scroll_id => { type => 'string' }, |
159
|
|
|
|
|
|
|
search => { type => 'bool' }, |
160
|
|
|
|
|
|
|
search_from => { type => 'number' }, |
161
|
|
|
|
|
|
|
search_indices => { type => 'list' }, |
162
|
|
|
|
|
|
|
search_query_hint => { type => 'string' }, |
163
|
|
|
|
|
|
|
search_scroll => { type => 'string' }, |
164
|
|
|
|
|
|
|
search_size => { type => 'number' }, |
165
|
|
|
|
|
|
|
search_source => { type => 'string' }, |
166
|
|
|
|
|
|
|
search_type => { |
167
|
|
|
|
|
|
|
options => [ |
168
|
|
|
|
|
|
|
'query_then_fetch', 'query_and_fetch', |
169
|
|
|
|
|
|
|
'dfs_query_then_fetch', 'dfs_query_and_fetch', |
170
|
|
|
|
|
|
|
'count', 'scan' |
171
|
|
|
|
|
|
|
], |
172
|
|
|
|
|
|
|
type => 'enum' |
173
|
|
|
|
|
|
|
}, |
174
|
|
|
|
|
|
|
search_types => { type => 'list' }, |
175
|
|
|
|
|
|
|
settings => { type => 'bool' }, |
176
|
|
|
|
|
|
|
size => { type => 'number' }, |
177
|
|
|
|
|
|
|
snapshot => { type => 'bool' }, |
178
|
|
|
|
|
|
|
snapshots => { type => 'number' }, |
179
|
|
|
|
|
|
|
sort => { type => 'list' }, |
180
|
|
|
|
|
|
|
source => { type => 'string' }, |
181
|
|
|
|
|
|
|
_source => { type => 'list', }, |
182
|
|
|
|
|
|
|
_source_exclude => { type => 'list', }, |
183
|
|
|
|
|
|
|
_source_include => { type => 'list', }, |
184
|
|
|
|
|
|
|
stats => { type => 'list' }, |
185
|
|
|
|
|
|
|
stop_words => { type => 'list' }, |
186
|
|
|
|
|
|
|
store => { type => 'bool' }, |
187
|
|
|
|
|
|
|
suggest_field => { type => 'string' }, |
188
|
|
|
|
|
|
|
suggest_mode => { |
189
|
|
|
|
|
|
|
default => 'missing', |
190
|
|
|
|
|
|
|
options => [ 'missing', 'popular', 'always' ], |
191
|
|
|
|
|
|
|
type => 'enum' |
192
|
|
|
|
|
|
|
}, |
193
|
|
|
|
|
|
|
suggest_size => { type => 'number' }, |
194
|
|
|
|
|
|
|
suggest_text => { type => 'string' }, |
195
|
|
|
|
|
|
|
term_statistics => { type => 'bool' }, |
196
|
|
|
|
|
|
|
text => { type => 'string' }, |
197
|
|
|
|
|
|
|
thread_pool => { type => 'bool' }, |
198
|
|
|
|
|
|
|
threads => { type => 'number' }, |
199
|
|
|
|
|
|
|
timeout => { type => 'duration' }, |
200
|
|
|
|
|
|
|
timestamp => { type => 'datetime' }, |
201
|
|
|
|
|
|
|
tokenizer => { type => 'string' }, |
202
|
|
|
|
|
|
|
transport => { type => 'bool' }, |
203
|
|
|
|
|
|
|
ts => { type => 'bool' }, |
204
|
|
|
|
|
|
|
ttl => { type => 'duration' }, |
205
|
|
|
|
|
|
|
type => { type => 'string' }, |
206
|
|
|
|
|
|
|
types => { type => 'list' }, |
207
|
|
|
|
|
|
|
v => { type => 'bool' }, |
208
|
|
|
|
|
|
|
version => { type => 'number' }, |
209
|
|
|
|
|
|
|
version_type => { |
210
|
|
|
|
|
|
|
type => 'enum', |
211
|
|
|
|
|
|
|
options => [ 'internal', 'external' ] |
212
|
|
|
|
|
|
|
}, |
213
|
|
|
|
|
|
|
wait_for_active_shards => { type => 'number' }, |
214
|
|
|
|
|
|
|
wait_for_completion => { type => 'bool' }, |
215
|
|
|
|
|
|
|
wait_for_merge => { type => 'bool' }, |
216
|
|
|
|
|
|
|
wait_for_nodes => { type => 'string' }, |
217
|
|
|
|
|
|
|
wait_for_relocating_shards => { type => 'number' }, |
218
|
|
|
|
|
|
|
wait_for_status => { |
219
|
|
|
|
|
|
|
default => undef, |
220
|
|
|
|
|
|
|
options => [ 'green', 'yellow', 'red' ], |
221
|
|
|
|
|
|
|
type => 'enum' |
222
|
|
|
|
|
|
|
}, |
223
|
|
|
|
|
|
|
warmer => { type => 'bool' } |
224
|
|
|
|
|
|
|
); |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
#=================================== |
227
|
|
|
|
|
|
|
sub qs_init { |
228
|
|
|
|
|
|
|
#=================================== |
229
|
42
|
|
|
42
|
|
77112
|
no warnings 'uninitialized'; |
|
42
|
|
|
|
|
104
|
|
|
42
|
|
|
|
|
11250
|
|
230
|
3738
|
|
|
3738
|
1
|
3875
|
my %qs; |
231
|
3738
|
|
|
|
|
5647
|
for (@_) { |
232
|
19278
|
|
50
|
|
|
44336
|
my $defn = $Params{$_} || die("Unknown query-string param ($_)\n"); |
233
|
19278
|
|
50
|
|
|
58724
|
$defn->{handler} ||= $Handler{ $defn->{type} } |
|
|
|
66
|
|
|
|
|
234
|
|
|
|
|
|
|
|| die "Unknown query-string parameter type ($defn->{type})\n"; |
235
|
19278
|
|
|
|
|
41601
|
$qs{$_} = $defn; |
236
|
|
|
|
|
|
|
} |
237
|
3738
|
|
|
|
|
15017
|
return \%qs; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
1; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=pod |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=encoding UTF-8 |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 NAME |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Elasticsearch::Util::API::QS - A utility class for query string parameters in the API |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 VERSION |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
version 1.05 |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 DESCRIPTION |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
This class contains a definition of each query string parameter that |
257
|
|
|
|
|
|
|
can be accepted by actions in the L<API|Elasticsearch::Role::API>. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 EXPORTS |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head2 C<qs_init()> |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
use Elasticsearch::Util::API::QS qw(qs_init); |
264
|
|
|
|
|
|
|
$handler = qs_init( @qs_params ); |
265
|
|
|
|
|
|
|
$qs_hash = $handler->($params); |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
The C<qs_init()> sub accepts a list of query string parameter names, |
268
|
|
|
|
|
|
|
and returns a handler which can extract those parameters from C<\%params> |
269
|
|
|
|
|
|
|
and return a hash of values to be passed as a query string. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
For instance: |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
$handler = qs_init(qw(fields size from)); |
274
|
|
|
|
|
|
|
$params = { fields =>['foo','bar'], size => 10, query=>\%query }; |
275
|
|
|
|
|
|
|
$qs_hash = $handler->($params); |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Would result in: |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
$qs_hash: { fields => 'foo,bar', size => 10}; |
280
|
|
|
|
|
|
|
$params: { query => \%query } |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head1 AUTHOR |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Clinton Gormley <drtech@cpan.org> |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Elasticsearch BV. |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
This is free software, licensed under: |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=cut |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
__END__ |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
# ABSTRACT: A utility class for query string parameters in the API |
299
|
|
|
|
|
|
|
|