|
| 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 |
0 commit comments