Skip to content

Commit b3494b3

Browse files
committed
[API] Adds open point in time
1 parent b7855d5 commit b3494b3

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 API
20+
module Actions
21+
# Open a point in time that can be used in subsequent searches
22+
#
23+
# @option arguments [List] :index A comma-separated list of index names to open point in time; use `_all` or empty string to perform the operation on all indices
24+
# @option arguments [String] :preference Specify the node or shard the operation should be performed on (default: random)
25+
# @option arguments [String] :routing Specific routing value
26+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
27+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, hidden, none, all)
28+
# @option arguments [String] :keep_alive Specific the time to live for the point in time
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/point-in-time-api.html
32+
#
33+
def open_point_in_time(arguments = {})
34+
headers = arguments.delete(:headers) || {}
35+
36+
arguments = arguments.clone
37+
38+
_index = arguments.delete(:index)
39+
40+
method = Elasticsearch::API::HTTP_POST
41+
path = if _index
42+
"#{Utils.__listify(_index)}/_pit"
43+
else
44+
"_pit"
45+
end
46+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
47+
48+
body = nil
49+
perform_request(method, path, params, body, headers).body
50+
end
51+
52+
# Register this action with its valid params when the module is loaded.
53+
#
54+
# @since 6.2.0
55+
ParamsRegistry.register(:open_point_in_time, [
56+
:preference,
57+
:routing,
58+
:ignore_unavailable,
59+
:expand_wildcards,
60+
:keep_alive
61+
].freeze)
62+
end
63+
end
64+
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#open_point_in_time' do
21+
let(:expected_args) do
22+
[
23+
'POST',
24+
url,
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
let (:url) { '_pit'}
32+
33+
it 'performs the request' do
34+
expect(client_double.open_point_in_time).to eq({})
35+
end
36+
37+
context 'with index' do
38+
let (:url) { 'foo/_pit'}
39+
40+
it 'performs the request' do
41+
expect(client_double.open_point_in_time(index: 'foo')).to eq({})
42+
end
43+
end
44+
end

0 commit comments

Comments
 (0)