Skip to content

Commit 38877ad

Browse files
committed
fix script query syntax when using newer Elasticsearch
Older versions expect the key "inline", newer expect "source".
1 parent c0b70ae commit 38877ad

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/MetaCPAN/Query/Search.pm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ sub _search_collapsed {
137137
my $es_query = $self->build_query( $search_term, $es_query_opts );
138138
my $source = delete $es_query->{_source};
139139

140+
my $script_key = $self->es->api_version ge '5_0' ? 'source' : 'inline';
141+
140142
$es_query->{aggregations} = {
141143
by_dist => {
142144
terms => {
@@ -156,8 +158,8 @@ sub _search_collapsed {
156158
max_score => {
157159
max => {
158160
script => {
159-
lang => "expression",
160-
inline => "_score",
161+
lang => "expression",
162+
$script_key => "_score",
161163
},
162164
},
163165
},
@@ -294,14 +296,16 @@ sub build_query {
294296
},
295297
};
296298

299+
my $script_key = $self->es->api_version ge '5_0' ? 'source' : 'inline';
300+
297301
$query = {
298302
function_score => {
299303
script_score => {
300304

301305
# prefer shorter module names
302306
script => {
303-
lang => 'expression',
304-
inline =>
307+
lang => 'expression',
308+
$script_key =>
305309
"_score - (doc['documentation_length'].value == 0 ? 26 : doc['documentation_length'].value)/400",
306310
},
307311
},

0 commit comments

Comments
 (0)