Skip to content

Commit 79ca5c2

Browse files
committed
[XPACK] Adds fleet.search
1 parent b59ac12 commit 79ca5c2

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 Fleet
22+
module Actions
23+
# Search API where the search will only be executed after specified checkpoints are available due to a refresh. This API is designed for internal use by the fleet server project.
24+
# This functionality is Experimental and may be changed or removed
25+
# completely in a future release. Elastic will take a best effort approach
26+
# to fix any issues, but experimental features are not subject to the
27+
# support SLA of official GA features.
28+
#
29+
# @option arguments [String] :index The index name to search.
30+
# @option arguments [List] :wait_for_checkpoints Comma separated list of checkpoints, one per shard
31+
# @option arguments [Time] :wait_for_checkpoints_timeout Explicit wait_for_checkpoints timeout
32+
# @option arguments [Boolean] :allow_partial_search_results Indicate if an error should be returned if there is a partial search failure or timeout
33+
# @option arguments [Hash] :headers Custom HTTP headers
34+
# @option arguments [Hash] :body The search definition using the Query DSL
35+
#
36+
# @see [TODO]
37+
#
38+
def search(arguments = {})
39+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
40+
41+
headers = arguments.delete(:headers) || {}
42+
43+
arguments = arguments.clone
44+
arguments[:index] = UNDERSCORE_ALL if !arguments[:index] && arguments[:type]
45+
46+
_index = arguments.delete(:index)
47+
48+
method = if arguments[:body]
49+
Elasticsearch::API::HTTP_POST
50+
else
51+
Elasticsearch::API::HTTP_GET
52+
end
53+
54+
path = "#{Elasticsearch::API::Utils.__listify(_index)}/_fleet/_fleet_search"
55+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
56+
57+
body = arguments[:body]
58+
perform_request(method, path, params, body, headers).body
59+
end
60+
61+
# Register this action with its valid params when the module is loaded.
62+
#
63+
# @since 6.2.0
64+
ParamsRegistry.register(:search, [
65+
:wait_for_checkpoints,
66+
:wait_for_checkpoints_timeout,
67+
:allow_partial_search_results
68+
].freeze)
69+
end
70+
end
71+
end
72+
end
73+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 'spec_helper'
19+
20+
describe 'client#fleet.search' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
'foo/_fleet/_fleet_search',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.fleet.search(index: 'foo')).to eq({})
33+
end
34+
35+
let(:client) do
36+
Class.new { include Elasticsearch::XPack::API }.new
37+
end
38+
39+
it 'requires the :index argument' do
40+
expect {
41+
client.fleet.search
42+
}.to raise_exception(ArgumentError)
43+
end
44+
end

0 commit comments

Comments
 (0)