Skip to content

Commit b56beea

Browse files
estolfopicandocodigo
authored andcommitted
[API] Ensure that index argument is considered in rank_eval api
1 parent 9ea2062 commit b56beea

File tree

2 files changed

+114
-1
lines changed

2 files changed

+114
-1
lines changed

elasticsearch-api/lib/elasticsearch/api/actions/rank_eval.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Actions
1717
def rank_eval(arguments={})
1818
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
1919
method = Elasticsearch::API::HTTP_GET
20-
path = "_rank_eval"
20+
path = Utils.__pathify(Utils.__escape(arguments[:index]), "_rank_eval")
2121
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
2222
body = arguments[:body]
2323

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
require 'spec_helper'
6+
7+
describe 'client#rank_eval' do
8+
9+
let(:expected_args) do
10+
[
11+
'GET',
12+
url,
13+
params,
14+
body
15+
]
16+
end
17+
18+
let(:params) do
19+
{}
20+
end
21+
22+
let(:body) do
23+
{}
24+
end
25+
26+
let(:url) do
27+
'_rank_eval'
28+
end
29+
30+
context 'when there is no body specified' do
31+
32+
let(:client) do
33+
Class.new { include Elasticsearch::API }.new
34+
end
35+
36+
it 'raises an exception' do
37+
expect {
38+
client.rank_eval(index: 'my_index')
39+
}.to raise_exception(ArgumentError)
40+
end
41+
end
42+
43+
context 'when an index is specified' do
44+
45+
let(:url) do
46+
'my_index/_rank_eval'
47+
end
48+
49+
it 'performs the request' do
50+
expect(client.rank_eval(index: 'my_index', body: {})).to eq({})
51+
end
52+
end
53+
54+
context 'when params are provided' do
55+
56+
let(:params) do
57+
{
58+
ignore_unavailable: true,
59+
allow_no_indices: false,
60+
expand_wildcards: 'open'
61+
}
62+
end
63+
64+
it 'performs the request' do
65+
expect(client_double.rank_eval(body: {},
66+
ignore_unavailable: true,
67+
allow_no_indices: false,
68+
expand_wildcards: 'open')).to eq({})
69+
end
70+
end
71+
72+
context 'when a body is specified' do
73+
74+
let(:body) do
75+
{
76+
"requests": [
77+
{
78+
"id": "JFK query",
79+
"request": { "query": { "match_all": {}}},
80+
"ratings": []
81+
}],
82+
"metric": {
83+
"expected_reciprocal_rank": {
84+
"maximum_relevance": 3,
85+
"k": 20
86+
}
87+
}
88+
}
89+
end
90+
91+
let(:url) do
92+
'my_index/_rank_eval'
93+
end
94+
95+
it 'performs the request' do
96+
expect(client_double.rank_eval(index: 'my_index',
97+
body: {
98+
"requests": [
99+
{
100+
"id": "JFK query",
101+
"request": { "query": { "match_all": {}}},
102+
"ratings": []
103+
}],
104+
"metric": {
105+
"expected_reciprocal_rank": {
106+
"maximum_relevance": 3,
107+
"k": 20
108+
}
109+
}
110+
})).to eq({})
111+
end
112+
end
113+
end

0 commit comments

Comments
 (0)