|
| 1 | +module Elasticsearch |
| 2 | + module API |
| 3 | + module Actions |
| 4 | + |
| 5 | + # Copy documents from one index to another, potentially changing |
| 6 | + # its settings, mappings and the documents itself. |
| 7 | + # |
| 8 | + # @example Copy documents into a different index |
| 9 | + # |
| 10 | + # client.reindex body: { source: { index: 'test1' }, dest: { index: 'test2' } } |
| 11 | + # |
| 12 | + # @example Limit the copied documents with a query |
| 13 | + # |
| 14 | + # client.reindex body: { |
| 15 | + # source: { |
| 16 | + # index: 'test1', |
| 17 | + # query: { terms: { category: ['one', 'two'] } } |
| 18 | + # }, |
| 19 | + # dest: { |
| 20 | + # index: 'test2' |
| 21 | + # } |
| 22 | + # } |
| 23 | + # |
| 24 | + # @example Remove a field from reindexed documents |
| 25 | + # |
| 26 | + # client.reindex body: { |
| 27 | + # source: { |
| 28 | + # index: 'test1' |
| 29 | + # }, |
| 30 | + # dest: { |
| 31 | + # index: 'test3' |
| 32 | + # }, |
| 33 | + # script: { |
| 34 | + # inline: 'ctx._source.remove("category")' |
| 35 | + # } |
| 36 | + # } |
| 37 | + # |
| 38 | + # @option arguments [Hash] :body The definition of the operation (source index, target index, ...) |
| 39 | + # (*Required*) |
| 40 | + # @option arguments [Boolean] :refresh Whether the affected indexes should be refreshed |
| 41 | + # @option arguments [Time] :timeout Time each individual bulk request should wait for shards |
| 42 | + # that are unavailable. (Default: 1m) |
| 43 | + # @option arguments [String] :consistency Explicit write consistency setting for the operation |
| 44 | + # (Options: one, quorum, all) |
| 45 | + # @option arguments [Boolean] :wait_for_completion Whether the request should block and wait until |
| 46 | + # the operation has completed |
| 47 | + # @option arguments [Float] :requests_per_second The throttling for this request in sub-requests per second. |
| 48 | + # 0 means set no throttling (default) |
| 49 | + # |
| 50 | + # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html |
| 51 | + # |
| 52 | + def reindex(arguments={}) |
| 53 | + raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] |
| 54 | + valid_params = [ |
| 55 | + :refresh, |
| 56 | + :timeout, |
| 57 | + :consistency, |
| 58 | + :wait_for_completion, |
| 59 | + :requests_per_second ] |
| 60 | + method = 'POST' |
| 61 | + path = "_reindex" |
| 62 | + params = Utils.__validate_and_extract_params arguments, valid_params |
| 63 | + body = arguments[:body] |
| 64 | + |
| 65 | + perform_request(method, path, params, body).body |
| 66 | + end |
| 67 | + end |
| 68 | + end |
| 69 | +end |
0 commit comments