|
| 1 | +module Elasticsearch |
| 2 | + module API |
| 3 | + module Actions |
| 4 | + |
| 5 | + # Perform multiple percolate operations in a single request, similar to the {#msearch} API |
| 6 | + # |
| 7 | + # Pass the percolate definitions as header-body pairs in the `:body` argument, as an Array of Hashes. |
| 8 | + # |
| 9 | + # @example Perform two different percolations in a single request |
| 10 | + # |
| 11 | + # client.mpercolate \ |
| 12 | + # body: [ |
| 13 | + # { percolate: { index: "my-index", type: "my-type" } }, |
| 14 | + # { doc: { message: "foo bar" } }, |
| 15 | + # { percolate: { index: "my-other-index", type: "my-other-type", id: "1" } }, |
| 16 | + # { } |
| 17 | + # ] |
| 18 | + # |
| 19 | + # @option arguments [String] :index The index of the document being count percolated to use as default |
| 20 | + # @option arguments [String] :type The type of the document being percolated to use as default. |
| 21 | + # @option arguments [Array<Hash>] The percolate request definitions (header & body pairs) (*Required*) |
| 22 | + # @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when |
| 23 | + # unavailable (missing or closed) |
| 24 | + # @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into |
| 25 | + # no concrete indices. (This includes `_all` string or when no |
| 26 | + # indices have been specified) |
| 27 | + # @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are |
| 28 | + # open, closed or both. (options: open, closed) |
| 29 | + # |
| 30 | + # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-percolate.html |
| 31 | + # |
| 32 | + def mpercolate(arguments={}) |
| 33 | + raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] |
| 34 | + method = HTTP_GET |
| 35 | + path = "_mpercolate" |
| 36 | + |
| 37 | + params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) |
| 38 | + body = arguments[:body] |
| 39 | + |
| 40 | + case |
| 41 | + when body.is_a?(Array) |
| 42 | + payload = body.map { |d| d.is_a?(String) ? d : Elasticsearch::API.serializer.dump(d) } |
| 43 | + payload << "" unless payload.empty? |
| 44 | + payload = payload.join("\n") |
| 45 | + else |
| 46 | + payload = body |
| 47 | + end |
| 48 | + |
| 49 | + perform_request(method, path, params, payload).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(:mpercolate, [ |
| 56 | + :ignore_unavailable, |
| 57 | + :allow_no_indices, |
| 58 | + :expand_wildcards, |
| 59 | + :percolate_format ].freeze) |
| 60 | + end |
| 61 | + end |
| 62 | +end |
0 commit comments