Skip to content

Commit f0a72d3

Browse files
committed
[XPACK] Updates EQL endpoints
1 parent fdd1a43 commit f0a72d3

File tree

5 files changed

+215
-1
lines changed

5 files changed

+215
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module Eql
22+
module Actions
23+
# Deletes an async EQL search by ID. If the search is still running, the search request will be cancelled. Otherwise, the saved search results are deleted.
24+
#
25+
# @option arguments [String] :id The async search ID
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
#
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/eql-search-api.html
29+
#
30+
def delete(arguments = {})
31+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
32+
33+
headers = arguments.delete(:headers) || {}
34+
35+
arguments = arguments.clone
36+
37+
_id = arguments.delete(:id)
38+
39+
method = Elasticsearch::API::HTTP_DELETE
40+
path = "_eql/search/#{Elasticsearch::API::Utils.__listify(_id)}"
41+
params = {}
42+
43+
body = nil
44+
perform_request(method, path, params, body, headers).body
45+
end
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module Eql
22+
module Actions
23+
# Returns async results from previously executed Event Query Language (EQL) search
24+
#
25+
# @option arguments [String] :id The async search ID
26+
# @option arguments [Time] :wait_for_completion_timeout Specify the time that the request should block waiting for the final response
27+
# @option arguments [Time] :keep_alive Update the time interval in which the results (partial or final) for this search will be available
28+
# @option arguments [Hash] :headers Custom HTTP headers
29+
#
30+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/eql-search-api.html
31+
#
32+
def get(arguments = {})
33+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
34+
35+
headers = arguments.delete(:headers) || {}
36+
37+
arguments = arguments.clone
38+
39+
_id = arguments.delete(:id)
40+
41+
method = Elasticsearch::API::HTTP_GET
42+
path = "_eql/search/#{Elasticsearch::API::Utils.__listify(_id)}"
43+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
44+
45+
body = nil
46+
perform_request(method, path, params, body, headers).body
47+
end
48+
49+
# Register this action with its valid params when the module is loaded.
50+
#
51+
# @since 6.2.0
52+
ParamsRegistry.register(:get, [
53+
:wait_for_completion_timeout,
54+
:keep_alive
55+
].freeze)
56+
end
57+
end
58+
end
59+
end
60+
end

elasticsearch-xpack/lib/elasticsearch/xpack/api/actions/eql/search.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ module Actions
2323
# Returns results matching a query expressed in Event Query Language (EQL)
2424
#
2525
# @option arguments [String] :index The name of the index to scope the operation
26+
# @option arguments [Time] :wait_for_completion_timeout Specify the time that the request should block waiting for the final response
27+
# @option arguments [Boolean] :keep_on_completion Control whether the response should be stored in the cluster if it completed within the provided [wait_for_completion] time (default: false)
28+
# @option arguments [Time] :keep_alive Update the time interval in which the results (partial or final) for this search will be available
2629
# @option arguments [Hash] :headers Custom HTTP headers
2730
# @option arguments [Hash] :body Eql request body. Use the `query` to limit the query scope. (*Required*)
2831
#
@@ -46,11 +49,20 @@ def search(arguments = {})
4649
end
4750

4851
path = "#{Elasticsearch::API::Utils.__listify(_index)}/_eql/search"
49-
params = {}
52+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
5053

5154
body = arguments[:body]
5255
perform_request(method, path, params, body, headers).body
5356
end
57+
58+
# Register this action with its valid params when the module is loaded.
59+
#
60+
# @since 6.2.0
61+
ParamsRegistry.register(:search, [
62+
:wait_for_completion_timeout,
63+
:keep_on_completion,
64+
:keep_alive
65+
].freeze)
5466
end
5567
end
5668
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackEqlDeleteTest < Minitest::Test
23+
context 'Eql: Delete' do
24+
subject { FakeClient.new }
25+
26+
should 'perform correct request' do
27+
subject.expects(:perform_request).with do |method, url, params, body|
28+
assert_equal 'DELETE', method
29+
assert_equal '_eql/search/test', url
30+
assert_equal({}, params)
31+
assert_equal body, nil
32+
true
33+
end.returns(FakeResponse.new)
34+
35+
subject.xpack.eql.delete(id: 'test')
36+
end
37+
38+
should 'raise argument error without id' do
39+
assert_raises ArgumentError do
40+
subject.xpack.eql.delete
41+
end
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackEqlGetTest < Minitest::Test
23+
context 'Eql: Get' do
24+
subject { FakeClient.new }
25+
26+
should 'perform correct request' do
27+
subject.expects(:perform_request).with do |method, url, params, body|
28+
assert_equal 'GET', method
29+
assert_equal '_eql/search/test', url
30+
assert_equal({}, params)
31+
assert_equal body, nil
32+
true
33+
end.returns(FakeResponse.new)
34+
35+
subject.xpack.eql.get(id: 'test')
36+
end
37+
38+
should 'raise argument error without id' do
39+
assert_raises ArgumentError do
40+
subject.xpack.eql.get
41+
end
42+
end
43+
end
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)