elasticsearch-api 7.4.0 → 7.5.0.pre.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +16 -23
  3. data/lib/elasticsearch/api/actions/abort_benchmark.rb +1 -2
  4. data/lib/elasticsearch/api/actions/benchmark.rb +2 -3
  5. data/lib/elasticsearch/api/actions/bulk.rb +35 -68
  6. data/lib/elasticsearch/api/actions/cat/aliases.rb +30 -52
  7. data/lib/elasticsearch/api/actions/cat/allocation.rb +36 -50
  8. data/lib/elasticsearch/api/actions/cat/count.rb +25 -46
  9. data/lib/elasticsearch/api/actions/cat/fielddata.rb +31 -33
  10. data/lib/elasticsearch/api/actions/cat/health.rb +27 -37
  11. data/lib/elasticsearch/api/actions/cat/help.rb +14 -10
  12. data/lib/elasticsearch/api/actions/cat/indices.rb +45 -62
  13. data/lib/elasticsearch/api/actions/cat/master.rb +24 -34
  14. data/lib/elasticsearch/api/actions/cat/nodeattrs.rb +20 -16
  15. data/lib/elasticsearch/api/actions/cat/nodes.rb +34 -46
  16. data/lib/elasticsearch/api/actions/cat/params_registry.rb +0 -1
  17. data/lib/elasticsearch/api/actions/cat/pending_tasks.rb +29 -35
  18. data/lib/elasticsearch/api/actions/cat/plugins.rb +21 -18
  19. data/lib/elasticsearch/api/actions/cat/recovery.rb +40 -56
  20. data/lib/elasticsearch/api/actions/cat/repositories.rb +21 -24
  21. data/lib/elasticsearch/api/actions/cat/segments.rb +29 -22
  22. data/lib/elasticsearch/api/actions/cat/shards.rb +38 -59
  23. data/lib/elasticsearch/api/actions/cat/snapshots.rb +32 -27
  24. data/lib/elasticsearch/api/actions/cat/tasks.rb +25 -19
  25. data/lib/elasticsearch/api/actions/cat/templates.rb +26 -18
  26. data/lib/elasticsearch/api/actions/cat/thread_pool.rb +36 -46
  27. data/lib/elasticsearch/api/actions/clear_scroll.rb +21 -8
  28. data/lib/elasticsearch/api/actions/cluster/allocation_explain.rb +15 -13
  29. data/lib/elasticsearch/api/actions/cluster/get_settings.rb +18 -18
  30. data/lib/elasticsearch/api/actions/cluster/health.rb +42 -44
  31. data/lib/elasticsearch/api/actions/cluster/params_registry.rb +0 -1
  32. data/lib/elasticsearch/api/actions/cluster/pending_tasks.rb +15 -17
  33. data/lib/elasticsearch/api/actions/cluster/put_settings.rb +20 -17
  34. data/lib/elasticsearch/api/actions/cluster/remote_info.rb +8 -6
  35. data/lib/elasticsearch/api/actions/cluster/reroute.rb +25 -37
  36. data/lib/elasticsearch/api/actions/cluster/state.rb +37 -41
  37. data/lib/elasticsearch/api/actions/cluster/stats.rb +20 -12
  38. data/lib/elasticsearch/api/actions/count.rb +52 -39
  39. data/lib/elasticsearch/api/actions/create.rb +25 -26
  40. data/lib/elasticsearch/api/actions/delete.rb +43 -36
  41. data/lib/elasticsearch/api/actions/delete_by_query.rb +74 -62
  42. data/lib/elasticsearch/api/actions/delete_by_query_rethrottle.rb +39 -0
  43. data/lib/elasticsearch/api/actions/delete_by_rethrottle.rb +4 -3
  44. data/lib/elasticsearch/api/actions/delete_script.rb +19 -13
  45. data/lib/elasticsearch/api/actions/exists.rb +44 -34
  46. data/lib/elasticsearch/api/actions/exists_source.rb +43 -25
  47. data/lib/elasticsearch/api/actions/explain.rb +46 -51
  48. data/lib/elasticsearch/api/actions/field_caps.rb +27 -20
  49. data/lib/elasticsearch/api/actions/get.rb +42 -41
  50. data/lib/elasticsearch/api/actions/get_script.rb +19 -14
  51. data/lib/elasticsearch/api/actions/get_source.rb +38 -44
  52. data/lib/elasticsearch/api/actions/index.rb +60 -89
  53. data/lib/elasticsearch/api/actions/indices/analyze.rb +19 -48
  54. data/lib/elasticsearch/api/actions/indices/clear_cache.rb +29 -41
  55. data/lib/elasticsearch/api/actions/indices/clone.rb +21 -21
  56. data/lib/elasticsearch/api/actions/indices/close.rb +28 -32
  57. data/lib/elasticsearch/api/actions/indices/create.rb +22 -70
  58. data/lib/elasticsearch/api/actions/indices/delete.rb +23 -35
  59. data/lib/elasticsearch/api/actions/indices/delete_alias.rb +24 -20
  60. data/lib/elasticsearch/api/actions/indices/delete_template.rb +18 -20
  61. data/lib/elasticsearch/api/actions/indices/exists.rb +32 -34
  62. data/lib/elasticsearch/api/actions/indices/exists_alias.rb +33 -29
  63. data/lib/elasticsearch/api/actions/indices/exists_template.rb +21 -16
  64. data/lib/elasticsearch/api/actions/indices/exists_type.rb +29 -29
  65. data/lib/elasticsearch/api/actions/indices/flush.rb +28 -28
  66. data/lib/elasticsearch/api/actions/indices/flush_synced.rb +23 -12
  67. data/lib/elasticsearch/api/actions/indices/forcemerge.rb +26 -41
  68. data/lib/elasticsearch/api/actions/indices/freeze.rb +7 -8
  69. data/lib/elasticsearch/api/actions/indices/get.rb +25 -19
  70. data/lib/elasticsearch/api/actions/indices/get_alias.rb +31 -23
  71. data/lib/elasticsearch/api/actions/indices/get_field_mapping.rb +42 -38
  72. data/lib/elasticsearch/api/actions/indices/get_mapping.rb +39 -31
  73. data/lib/elasticsearch/api/actions/indices/get_settings.rb +34 -37
  74. data/lib/elasticsearch/api/actions/indices/get_template.rb +21 -23
  75. data/lib/elasticsearch/api/actions/indices/get_upgrade.rb +48 -0
  76. data/lib/elasticsearch/api/actions/indices/open.rb +24 -21
  77. data/lib/elasticsearch/api/actions/indices/params_registry.rb +0 -1
  78. data/lib/elasticsearch/api/actions/indices/put_alias.rb +25 -27
  79. data/lib/elasticsearch/api/actions/indices/put_mapping.rb +40 -39
  80. data/lib/elasticsearch/api/actions/indices/put_settings.rb +30 -37
  81. data/lib/elasticsearch/api/actions/indices/put_template.rb +23 -23
  82. data/lib/elasticsearch/api/actions/indices/recovery.rb +20 -23
  83. data/lib/elasticsearch/api/actions/indices/refresh.rb +22 -26
  84. data/lib/elasticsearch/api/actions/indices/rollover.rb +28 -19
  85. data/lib/elasticsearch/api/actions/indices/segments.rb +24 -17
  86. data/lib/elasticsearch/api/actions/indices/shard_stores.rb +27 -15
  87. data/lib/elasticsearch/api/actions/indices/shrink.rb +23 -17
  88. data/lib/elasticsearch/api/actions/indices/split.rb +23 -17
  89. data/lib/elasticsearch/api/actions/indices/stats.rb +53 -104
  90. data/lib/elasticsearch/api/actions/indices/unfreeze.rb +7 -7
  91. data/lib/elasticsearch/api/actions/indices/update_aliases.rb +15 -32
  92. data/lib/elasticsearch/api/actions/indices/upgrade.rb +26 -16
  93. data/lib/elasticsearch/api/actions/indices/validate_query.rb +46 -59
  94. data/lib/elasticsearch/api/actions/info.rb +9 -6
  95. data/lib/elasticsearch/api/actions/ingest/delete_pipeline.rb +18 -12
  96. data/lib/elasticsearch/api/actions/ingest/get_pipeline.rb +21 -11
  97. data/lib/elasticsearch/api/actions/ingest/params_registry.rb +0 -1
  98. data/lib/elasticsearch/api/actions/ingest/processor_grok.rb +12 -13
  99. data/lib/elasticsearch/api/actions/ingest/put_pipeline.rb +19 -14
  100. data/lib/elasticsearch/api/actions/ingest/simulate.rb +23 -13
  101. data/lib/elasticsearch/api/actions/mget.rb +37 -44
  102. data/lib/elasticsearch/api/actions/msearch.rb +54 -54
  103. data/lib/elasticsearch/api/actions/msearch_template.rb +46 -35
  104. data/lib/elasticsearch/api/actions/mtermvectors.rb +39 -35
  105. data/lib/elasticsearch/api/actions/nodes/hot_threads.rb +30 -25
  106. data/lib/elasticsearch/api/actions/nodes/info.rb +29 -63
  107. data/lib/elasticsearch/api/actions/nodes/params_registry.rb +0 -1
  108. data/lib/elasticsearch/api/actions/nodes/reload_secure_settings.rb +24 -22
  109. data/lib/elasticsearch/api/actions/nodes/shutdown.rb +4 -4
  110. data/lib/elasticsearch/api/actions/nodes/stats.rb +43 -36
  111. data/lib/elasticsearch/api/actions/nodes/usage.rb +31 -10
  112. data/lib/elasticsearch/api/actions/params_registry.rb +0 -1
  113. data/lib/elasticsearch/api/actions/ping.rb +12 -13
  114. data/lib/elasticsearch/api/actions/put_script.rb +26 -30
  115. data/lib/elasticsearch/api/actions/rank_eval.rb +24 -15
  116. data/lib/elasticsearch/api/actions/reindex.rb +25 -48
  117. data/lib/elasticsearch/api/actions/reindex_rethrottle.rb +18 -12
  118. data/lib/elasticsearch/api/actions/remote/info.rb +1 -2
  119. data/lib/elasticsearch/api/actions/render_search_template.rb +17 -15
  120. data/lib/elasticsearch/api/actions/scripts_painless_execute.rb +8 -6
  121. data/lib/elasticsearch/api/actions/scroll.rb +28 -51
  122. data/lib/elasticsearch/api/actions/search.rb +104 -165
  123. data/lib/elasticsearch/api/actions/search_shards.rb +31 -28
  124. data/lib/elasticsearch/api/actions/search_template.rb +48 -40
  125. data/lib/elasticsearch/api/actions/snapshot/cleanup_repository.rb +44 -0
  126. data/lib/elasticsearch/api/actions/snapshot/create.rb +22 -29
  127. data/lib/elasticsearch/api/actions/snapshot/create_repository.rb +19 -24
  128. data/lib/elasticsearch/api/actions/snapshot/delete.rb +20 -22
  129. data/lib/elasticsearch/api/actions/snapshot/delete_repository.rb +16 -18
  130. data/lib/elasticsearch/api/actions/snapshot/get.rb +22 -31
  131. data/lib/elasticsearch/api/actions/snapshot/get_repository.rb +21 -25
  132. data/lib/elasticsearch/api/actions/snapshot/params_registry.rb +0 -1
  133. data/lib/elasticsearch/api/actions/snapshot/restore.rb +21 -32
  134. data/lib/elasticsearch/api/actions/snapshot/status.rb +23 -24
  135. data/lib/elasticsearch/api/actions/snapshot/verify_repository.rb +18 -13
  136. data/lib/elasticsearch/api/actions/tasks/cancel.rb +19 -13
  137. data/lib/elasticsearch/api/actions/tasks/get.rb +16 -13
  138. data/lib/elasticsearch/api/actions/tasks/list.rb +20 -18
  139. data/lib/elasticsearch/api/actions/tasks/params_registry.rb +0 -1
  140. data/lib/elasticsearch/api/actions/termvectors.rb +52 -70
  141. data/lib/elasticsearch/api/actions/update.rb +53 -98
  142. data/lib/elasticsearch/api/actions/update_by_query.rb +77 -66
  143. data/lib/elasticsearch/api/actions/update_by_query_rethrottle.rb +17 -11
  144. data/lib/elasticsearch/api/version.rb +1 -1
  145. data/spec/elasticsearch/api/actions/cat/segments_spec.rb +9 -11
  146. data/spec/elasticsearch/api/actions/cluster/put_settings_spec.rb +1 -1
  147. data/spec/elasticsearch/api/actions/count_spec.rb +8 -8
  148. data/spec/elasticsearch/api/actions/delete_by_query_spec.rb +12 -7
  149. data/spec/elasticsearch/api/actions/delete_script_spec.rb +0 -14
  150. data/spec/elasticsearch/api/actions/exists_document_spec.rb +1 -1
  151. data/spec/elasticsearch/api/actions/get_document_source_spec.rb +1 -1
  152. data/spec/elasticsearch/api/actions/index_document_spec.rb +6 -15
  153. data/spec/elasticsearch/api/actions/indices/analyze_spec.rb +0 -4
  154. data/spec/elasticsearch/api/actions/indices/clear_cache_spec.rb +1 -5
  155. data/spec/elasticsearch/api/actions/indices/clone_spec.rb +1 -1
  156. data/spec/elasticsearch/api/actions/indices/delete_alias_spec.rb +2 -2
  157. data/spec/elasticsearch/api/actions/indices/get_spec.rb +0 -11
  158. data/spec/elasticsearch/api/actions/indices/put_alias_spec.rb +3 -3
  159. data/spec/elasticsearch/api/actions/indices/put_mapping_spec.rb +3 -3
  160. data/spec/elasticsearch/api/actions/indices/stats_spec.rb +0 -1
  161. data/spec/elasticsearch/api/actions/nodes/hot_threads_spec.rb +3 -3
  162. data/spec/elasticsearch/api/actions/put_script_spec.rb +20 -15
  163. data/spec/elasticsearch/api/actions/render_search_template_spec.rb +23 -7
  164. data/spec/elasticsearch/api/actions/scroll_spec.rb +37 -0
  165. data/spec/elasticsearch/api/actions/search_spec.rb +0 -15
  166. data/spec/elasticsearch/api/actions/tasks/list_spec.rb +0 -11
  167. data/spec/elasticsearch/api/actions/update_document_spec.rb +3 -7
  168. data/spec/rest_yaml_tests_helper.rb +12 -0
  169. data/utils/Gemfile +1 -0
  170. data/utils/Thorfile +0 -1
  171. data/utils/thor/generate_source.rb +192 -85
  172. data/utils/thor/generator/endpoint_specifics.rb +157 -0
  173. data/utils/thor/generator/files_helper.rb +37 -0
  174. data/utils/thor/lister.rb +3 -4
  175. data/utils/thor/templates/_documentation_top.erb +27 -0
  176. data/utils/thor/templates/_method_setup.erb +35 -0
  177. data/utils/thor/templates/_params_registry.erb +12 -0
  178. data/utils/thor/templates/_perform_request.erb +37 -0
  179. data/utils/thor/templates/method.erb +59 -0
  180. data/utils/thor/templates/{ruby/test.erb → test.erb} +0 -0
  181. data/utils/thor/templates/{ruby/test_helper.rb → test_helper.rb} +0 -0
  182. metadata +19 -11
  183. data/spec/elasticsearch/api/actions/scoll_spec.rb +0 -21
  184. data/utils/thor/generate_api.rb +0 -193
  185. data/utils/thor/templates/ruby/method.erb +0 -62
@@ -7,7 +7,6 @@ module Elasticsearch
7
7
  module Tasks
8
8
  module Actions
9
9
  module ParamsRegistry
10
-
11
10
  extend self
12
11
 
13
12
  # A Mapping of all the actions to their list of valid params.
@@ -5,43 +5,11 @@
5
5
  module Elasticsearch
6
6
  module API
7
7
  module Actions
8
-
9
- # Return information and statistics about terms in the fields of a particular document
10
- #
11
- # @example Get statistics for an indexed document
12
- #
13
- # client.indices.create index: 'my_index',
14
- # body: {
15
- # mappings: {
16
- # properties: {
17
- # text: {
18
- # type: 'string',
19
- # term_vector: 'with_positions_offsets_payloads'
20
- # }
21
- # }
22
- # }
23
- # }
24
- #
25
- # client.index index: 'my_index', type: 'my_type', id: '1', body: { text: 'Foo Bar Fox' }
26
- #
27
- # client.termvectors index: 'my_index', type: 'my_type', id: '1'
28
- # # => { ..., "term_vectors" => { "text" => { "field_statistics" => { ... }, "terms" => { "bar" => ... } } }
29
- #
30
- #
31
- # @example Get statistics for an arbitrary document
8
+ # Returns information and statistics about terms in the fields of a particular document.
32
9
  #
33
- # client.termvector index: 'my_index', type: 'my_type',
34
- # body: {
35
- # doc: {
36
- # text: 'Foo Bar Fox'
37
- # }
38
- # }
39
- # # => { ..., "term_vectors" => { "text" => { "field_statistics" => { ... }, "terms" => { "bar" => ... } } }
40
- #
41
- # @option arguments [String] :index The index in which the document resides. (*Required*)
42
- # @option arguments [String] :type The type of the document.
10
+ # @option arguments [String] :index The index in which the document resides. (*Required*)
43
11
  # @option arguments [String] :id The id of the document, when not specified a doc param should be supplied.
44
- # @option arguments [Hash] :body Define parameters and or supply a document to get termvectors for. See documentation.
12
+ # @option arguments [String] :type The type of the document.
45
13
  # @option arguments [Boolean] :term_statistics Specifies if total term frequency and document frequency should be returned.
46
14
  # @option arguments [Boolean] :field_statistics Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned.
47
15
  # @option arguments [List] :fields A comma-separated list of fields to return.
@@ -50,57 +18,71 @@ module Elasticsearch
50
18
  # @option arguments [Boolean] :payloads Specifies if term payloads should be returned.
51
19
  # @option arguments [String] :preference Specify the node or shard the operation should be performed on (default: random).
52
20
  # @option arguments [String] :routing Specific routing value.
53
- # @option arguments [String] :parent Parent id of documents.
54
21
  # @option arguments [Boolean] :realtime Specifies if request is real-time as opposed to near-real-time (default: true).
55
22
  # @option arguments [Number] :version Explicit version number for concurrency control
56
- # @option arguments [String] :version_type Specific version type (options: internal, external, external_gte, force)
23
+ # @option arguments [String] :version_type Specific version type
24
+ # (options: internal,external,external_gte,force)
25
+
26
+ # @option arguments [Hash] :body Define parameters and or supply a document to get termvectors for. See documentation.
57
27
  #
58
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html
28
+ # *Deprecation notice*:
29
+ # Specifying types in urls has been deprecated
30
+ # Deprecated since version 7.0.0
59
31
  #
60
- def termvectors(arguments={})
32
+ #
33
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/7.5/docs-termvectors.html
34
+ #
35
+ def termvectors(arguments = {})
61
36
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
62
- method = HTTP_GET
63
- endpoint = arguments.delete(:endpoint) || '_termvectors'
64
37
 
65
- if arguments[:type]
66
- path = Utils.__pathify Utils.__escape(arguments[:index]),
67
- arguments[:type],
68
- arguments[:id],
69
- endpoint
70
- else
71
- path = Utils.__pathify Utils.__escape(arguments[:index]),
72
- endpoint,
73
- arguments[:id]
74
- end
38
+ arguments = arguments.clone
39
+
40
+ _index = arguments.delete(:index)
41
+
42
+ _id = arguments.delete(:id)
43
+
44
+ _type = arguments.delete(:type)
45
+
46
+ method = Elasticsearch::API::HTTP_GET
47
+
48
+ endpoint = arguments.delete(:endpoint) || '_termvectors'
49
+ path = if _index && _type && _id
50
+ "#{Utils.__listify(_index)}/#{Utils.__listify(_type)}/#{Utils.__listify(_id)}/#{endpoint}"
51
+ elsif _index && _type
52
+ "#{Utils.__listify(_index)}/#{Utils.__listify(_type)}/#{endpoint}"
53
+ elsif _index && _id
54
+ "#{Utils.__listify(_index)}/#{endpoint}/#{Utils.__listify(_id)}"
55
+ else
56
+ "#{Utils.__listify(_index)}/#{endpoint}"
57
+ end
75
58
 
76
59
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
77
- body = arguments[:body]
78
60
 
61
+ body = arguments[:body]
79
62
  perform_request(method, path, params, body).body
80
63
  end
81
64
 
82
- # @deprecated Use the plural version, {#termvectors}
65
+ # Deprecated: Use the plural version, {#termvectors}
83
66
  #
84
- def termvector(arguments={})
85
- termvectors(arguments.merge :endpoint => '_termvector')
67
+ def termvector(arguments = {})
68
+ termvectors(arguments.merge endpoint: '_termvector')
86
69
  end
87
-
88
70
  # Register this action with its valid params when the module is loaded.
89
71
  #
90
- # @since 6.1.1
72
+ # @since 6.2.0
91
73
  ParamsRegistry.register(:termvectors, [
92
- :term_statistics,
93
- :field_statistics,
94
- :fields,
95
- :offsets,
96
- :positions,
97
- :payloads,
98
- :preference,
99
- :routing,
100
- :parent,
101
- :realtime,
102
- :version,
103
- :version_type ].freeze)
74
+ :term_statistics,
75
+ :field_statistics,
76
+ :fields,
77
+ :offsets,
78
+ :positions,
79
+ :payloads,
80
+ :preference,
81
+ :routing,
82
+ :realtime,
83
+ :version,
84
+ :version_type
85
+ ].freeze)
86
+ end
104
87
  end
105
- end
106
88
  end
@@ -5,92 +5,56 @@
5
5
  module Elasticsearch
6
6
  module API
7
7
  module Actions
8
+ # Updates a document with a script or partial document.
9
+ #
10
+ # @option arguments [String] :id Document ID
11
+ # @option arguments [String] :index The name of the index
12
+ # @option arguments [String] :type The type of the document *Deprecated*
13
+ # @option arguments [String] :wait_for_active_shards Sets the number of shard copies that must be active before proceeding with the update operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)
14
+ # @option arguments [List] :_source True or false to return the _source field or not, or a list of fields to return
15
+ # @option arguments [List] :_source_excludes A list of fields to exclude from the returned _source field
16
+ # @option arguments [List] :_source_includes A list of fields to extract and return from the _source field
17
+ # @option arguments [String] :lang The script language (default: painless)
18
+ # @option arguments [String] :refresh If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes.
19
+ # (options: true,false,wait_for)
8
20
 
9
- # Update a document without sending the whole document in the request ("partial update").
10
- #
11
- # Send either a partial document (`doc` ) which will be deeply merged into an existing document,
12
- # or a `script`, which will update the document content, in the `:body` argument.
13
- #
14
- # The partial update operation allows you to limit the amount of data you send over the wire and
15
- # reduces the chance of failed updates due to conflict.
16
- #
17
- # Specify the `:version` and `:retry_on_conflict` arguments to balance convenience and consistency.
18
- #
19
- # @example Update document _title_ using partial `doc`-ument
20
- #
21
- # client.update index: 'myindex', type: 'mytype', id: '1',
22
- # body: { doc: { title: 'Updated' } }
23
- #
24
- # @example Add a tag to document `tags` property using a `script`
25
- #
26
- # client.update index: 'myindex', type: 'mytype', id: '1',
27
- # body: { script: { source: 'ctx._source.tags.add(params.tag)', params: { tag: 'x' } } }
28
- #
29
- # @example Increment a document counter by 1 _or_ initialize it, when the document does not exist
30
- #
31
- # client.update index: 'myindex', type: 'mytype', id: '666',
32
- # body: { script: 'ctx._source.counter += 1', upsert: { counter: 1 } }
33
- #
34
- # @example Delete a document if it's tagged "to-delete"
35
- #
36
- # client.update index: 'myindex', type: 'mytype', id: '1',
37
- # body: { script: 'ctx._source.tags.contains(params.tag) ? ctx.op = "delete" : ctx.op = "none"',
38
- # params: { tag: 'to-delete' } }
39
- #
40
- # @option arguments [String] :id Document ID (*Required*)
41
- # @option arguments [Number,List] :ignore The list of HTTP errors to ignore; only `404` supported at the moment
42
- # @option arguments [String] :index The name of the index (*Required*)
43
- # @option arguments [String] :type The type of the document (*Required*)
44
- # @option arguments [Hash] :body The request definition using either `script` or partial `doc` (*Required*)
45
- # @option arguments [String] :consistency Explicit write consistency setting for the operation
46
- # (options: one, quorum, all)
47
- # @option arguments [List] :fields A comma-separated list of fields to return in the response
48
- # @option arguments [Boolean] :include_type_name Whether a type should be expected in the body of the mappings.
49
- # @option arguments [String] :lang The script language (default: mvel)
50
- # @option arguments [String] :parent ID of the parent document
51
- # @option arguments [String] :percolate Perform percolation during the operation;
52
- # use specific registered query name, attribute, or wildcard
53
- # @option arguments [Boolean] :refresh Refresh the index after performing the operation
54
- # @option arguments [String] :replication Specific replication type (options: sync, async)
55
- # @option arguments [Number] :retry_on_conflict Specify how many times should the operation be retried
56
- # when a conflict occurs (default: 0)
21
+ # @option arguments [Number] :retry_on_conflict Specify how many times should the operation be retried when a conflict occurs (default: 0)
57
22
  # @option arguments [String] :routing Specific routing value
58
- # @option arguments [String] :script The URL-encoded script definition (instead of using request body)
59
- # @option arguments [String] :_source Specify whether the _source field should be returned,
60
- # or a list of fields to return
61
- # @option arguments [String] :_source_exclude A list of fields to exclude from the returned _source field
62
- # @option arguments [String] :_source_include A list of fields to extract and return from the _source field
63
23
  # @option arguments [Time] :timeout Explicit operation timeout
64
- # @option arguments [Time] :timestamp Explicit timestamp for the document
65
- # @option arguments [Duration] :ttl Expiration time for the document
66
- # @option arguments [Number] :version Explicit version number for concurrency control
67
- # @option arguments [Number] :version_type Explicit version number for concurrency control
24
+ # @option arguments [Number] :if_seq_no only perform the update operation if the last operation that has changed the document has the specified sequence number
25
+ # @option arguments [Number] :if_primary_term only perform the update operation if the last operation that has changed the document has the specified primary term
26
+
27
+ # @option arguments [Hash] :body The request definition requires either `script` or partial `doc` (*Required*)
28
+ #
29
+ # *Deprecation notice*:
30
+ # Specifying types in urls has been deprecated
31
+ # Deprecated since version 7.0.0
68
32
  #
69
- # @since 0.20
70
33
  #
71
- # @see http://elasticsearch.org/guide/reference/api/update/
34
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/7.5/docs-update.html
72
35
  #
73
- def update(arguments={})
36
+ def update(arguments = {})
37
+ raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
74
38
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
75
- raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
76
- arguments[:type] ||= DEFAULT_DOC
77
- method = HTTP_POST
39
+ raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
78
40
 
79
- if arguments[:type]
80
- path = Utils.__pathify Utils.__escape(arguments[:index]),
81
- Utils.__escape(arguments[:type]),
82
- Utils.__escape(arguments[:id]),
83
- '_update'
84
- else
85
- path = Utils.__pathify Utils.__escape(arguments[:index]),
86
- '_update',
87
- Utils.__escape(arguments[:id])
88
- end
41
+ arguments = arguments.clone
42
+
43
+ _id = arguments.delete(:id)
89
44
 
45
+ _index = arguments.delete(:index)
46
+
47
+ _type = arguments.delete(:type)
48
+
49
+ method = Elasticsearch::API::HTTP_POST
50
+ path = if _index && _type && _id
51
+ "#{Utils.__listify(_index)}/#{Utils.__listify(_type)}/#{Utils.__listify(_id)}/_update"
52
+ else
53
+ "#{Utils.__listify(_index)}/_update/#{Utils.__listify(_id)}"
54
+ end
90
55
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
91
- body = arguments[:body]
92
- params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
93
56
 
57
+ body = arguments[:body]
94
58
  if Array(arguments[:ignore]).include?(404)
95
59
  Utils.__rescue_from_not_found { perform_request(method, path, params, body).body }
96
60
  else
@@ -100,29 +64,20 @@ module Elasticsearch
100
64
 
101
65
  # Register this action with its valid params when the module is loaded.
102
66
  #
103
- # @since 6.1.1
67
+ # @since 6.2.0
104
68
  ParamsRegistry.register(:update, [
105
- :consistency,
106
- :fields,
107
- :include_type_name,
108
- :lang,
109
- :parent,
110
- :percolate,
111
- :refresh,
112
- :replication,
113
- :retry_on_conflict,
114
- :routing,
115
- :script,
116
- :_source,
117
- :_source_include,
118
- :_source_exclude,
119
- :timeout,
120
- :timestamp,
121
- :ttl,
122
- :version,
123
- :version_type,
124
- :if_seq_no,
125
- :if_primary_term ].freeze)
69
+ :wait_for_active_shards,
70
+ :_source,
71
+ :_source_excludes,
72
+ :_source_includes,
73
+ :lang,
74
+ :refresh,
75
+ :retry_on_conflict,
76
+ :routing,
77
+ :timeout,
78
+ :if_seq_no,
79
+ :if_primary_term
80
+ ].freeze)
81
+ end
126
82
  end
127
- end
128
83
  end
@@ -5,42 +5,38 @@
5
5
  module Elasticsearch
6
6
  module API
7
7
  module Actions
8
-
9
- # Process every document matching a query, potentially updating it
10
- #
11
- # @example Update all documents in the index, eg. to pick up new mappings
12
- #
13
- # client.update_by_query index: 'articles'
14
- #
15
- # @example Update a property of documents matching a query in the index
16
- #
17
- # client.update_by_query index: 'article',
18
- # body: {
19
- # script: { inline: 'ctx._source.views += 1' },
20
- # query: { match: { title: 'foo' } }
21
- # }
8
+ # Performs an update on every document in the index without changing the source,
9
+ # for example to pick up a mapping change.
22
10
  #
23
- # @option arguments [List] :index A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices (*Required*)
11
+ # @option arguments [List] :index A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices (*Required*)
24
12
  # @option arguments [List] :type A comma-separated list of document types to search; leave empty to perform the operation on all types
25
- # @option arguments [Hash] :body The search definition using the Query DSL
26
13
  # @option arguments [String] :analyzer The analyzer to use for the query string
27
14
  # @option arguments [Boolean] :analyze_wildcard Specify whether wildcard and prefix queries should be analyzed (default: false)
28
- # @option arguments [String] :default_operator The default operator for query string query (AND or OR) (options: AND, OR)
15
+ # @option arguments [String] :default_operator The default operator for query string query (AND or OR)
16
+ # (options: AND,OR)
17
+
29
18
  # @option arguments [String] :df The field to use as default where no field prefix is given in the query string
30
19
  # @option arguments [Number] :from Starting offset (default: 0)
31
20
  # @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
32
21
  # @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
33
- # @option arguments [String] :conflicts What to do when the update by query hits version conflicts? (options: abort, proceed)
34
- # @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, none, all)
22
+ # @option arguments [String] :conflicts What to do when the update by query hits version conflicts?
23
+ # (options: abort,proceed)
24
+
25
+ # @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both.
26
+ # (options: open,closed,none,all)
27
+
35
28
  # @option arguments [Boolean] :lenient Specify whether format-based query failures (such as providing text to a numeric field) should be ignored
36
29
  # @option arguments [String] :pipeline Ingest pipeline to set on index requests made by this action. (default: none)
37
30
  # @option arguments [String] :preference Specify the node or shard the operation should be performed on (default: random)
38
31
  # @option arguments [String] :q Query in the Lucene query string syntax
39
32
  # @option arguments [List] :routing A comma-separated list of specific routing values
40
33
  # @option arguments [Time] :scroll Specify how long a consistent view of the index should be maintained for scrolled search
41
- # @option arguments [String] :search_type Search operation type (options: query_then_fetch, dfs_query_then_fetch)
34
+ # @option arguments [String] :search_type Search operation type
35
+ # (options: query_then_fetch,dfs_query_then_fetch)
36
+
42
37
  # @option arguments [Time] :search_timeout Explicit timeout for each search request. Defaults to no timeout.
43
- # @option arguments [Number] :size Number of hits to return (default: 10)
38
+ # @option arguments [Number] :size Deprecated, please use `max_docs` instead
39
+ # @option arguments [Number] :max_docs Maximum number of documents to process (default: all documents)
44
40
  # @option arguments [List] :sort A comma-separated list of <field>:<direction> pairs
45
41
  # @option arguments [List] :_source True or false to return the _source field or not, or a list of fields to return
46
42
  # @option arguments [List] :_source_excludes A list of fields to exclude from the returned _source field
@@ -50,69 +46,84 @@ module Elasticsearch
50
46
  # @option arguments [Boolean] :version Specify whether to return document version as part of a hit
51
47
  # @option arguments [Boolean] :version_type Should the document increment the version number (internal) on hit or not (reindex)
52
48
  # @option arguments [Boolean] :request_cache Specify if request cache should be used for this request or not, defaults to index level setting
53
- # @option arguments [Boolean] :refresh Should the effected indexes be refreshed?
49
+ # @option arguments [Boolean] :refresh Should the affected indexes be refreshed?
54
50
  # @option arguments [Time] :timeout Time each individual bulk request should wait for shards that are unavailable.
55
51
  # @option arguments [String] :wait_for_active_shards Sets the number of shard copies that must be active before proceeding with the update by query operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)
56
52
  # @option arguments [Number] :scroll_size Size on the scroll request powering the update by query
57
53
  # @option arguments [Boolean] :wait_for_completion Should the request should block until the update by query operation is complete.
58
54
  # @option arguments [Number] :requests_per_second The throttle to set on this request in sub-requests per second. -1 means no throttle.
59
55
  # @option arguments [Number] :slices The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks.
56
+
57
+ # @option arguments [Hash] :body The search definition using the Query DSL
58
+ #
59
+ # *Deprecation notice*:
60
+ # Specifying types in urls has been deprecated
61
+ # Deprecated since version 7.0.0
60
62
  #
61
- # @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html
62
63
  #
63
- def update_by_query(arguments={})
64
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/7.5/docs-update-by-query.html
65
+ #
66
+ def update_by_query(arguments = {})
64
67
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
65
- method = HTTP_POST
66
68
 
67
- path = Utils.__pathify Utils.__listify(arguments[:index]),
68
- Utils.__listify(arguments[:type]),
69
- '/_update_by_query'
69
+ arguments = arguments.clone
70
70
 
71
- params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
71
+ _index = arguments.delete(:index)
72
72
 
73
- body = arguments[:body]
73
+ _type = arguments.delete(:type)
74
74
 
75
+ method = Elasticsearch::API::HTTP_POST
76
+ path = if _index && _type
77
+ "#{Utils.__listify(_index)}/#{Utils.__listify(_type)}/_update_by_query"
78
+ else
79
+ "#{Utils.__listify(_index)}/_update_by_query"
80
+ end
81
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
82
+
83
+ body = arguments[:body]
75
84
  perform_request(method, path, params, body).body
76
85
  end
77
86
 
78
87
  # Register this action with its valid params when the module is loaded.
79
88
  #
80
- # @since 6.1.1
89
+ # @since 6.2.0
81
90
  ParamsRegistry.register(:update_by_query, [
82
- :analyzer,
83
- :analyze_wildcard,
84
- :default_operator,
85
- :df,
86
- :from,
87
- :ignore_unavailable,
88
- :allow_no_indices,
89
- :conflicts,
90
- :expand_wildcards,
91
- :lenient,
92
- :pipeline,
93
- :preference,
94
- :q,
95
- :routing,
96
- :scroll,
97
- :search_type,
98
- :search_timeout,
99
- :size,
100
- :sort,
101
- :_source,
102
- :_source_excludes,
103
- :_source_includes,
104
- :terminate_after,
105
- :stats,
106
- :version,
107
- :version_type,
108
- :request_cache,
109
- :refresh,
110
- :timeout,
111
- :wait_for_active_shards,
112
- :scroll_size,
113
- :wait_for_completion,
114
- :requests_per_second,
115
- :slices ].freeze)
91
+ :analyzer,
92
+ :analyze_wildcard,
93
+ :default_operator,
94
+ :df,
95
+ :from,
96
+ :ignore_unavailable,
97
+ :allow_no_indices,
98
+ :conflicts,
99
+ :expand_wildcards,
100
+ :lenient,
101
+ :pipeline,
102
+ :preference,
103
+ :q,
104
+ :routing,
105
+ :scroll,
106
+ :search_type,
107
+ :search_timeout,
108
+ :size,
109
+ :max_docs,
110
+ :sort,
111
+ :_source,
112
+ :_source_excludes,
113
+ :_source_includes,
114
+ :terminate_after,
115
+ :stats,
116
+ :version,
117
+ :version_type,
118
+ :request_cache,
119
+ :refresh,
120
+ :timeout,
121
+ :wait_for_active_shards,
122
+ :scroll_size,
123
+ :wait_for_completion,
124
+ :requests_per_second,
125
+ :slices
126
+ ].freeze)
127
+ end
116
128
  end
117
- end
118
129
  end