Skip to content

Commit 263cb55

Browse files
committed
[API] Fix accidental overwrite of index code
1 parent c2b0e70 commit 263cb55

File tree

1 file changed

+38
-14
lines changed
  • elasticsearch-api/lib/elasticsearch/api/actions

1 file changed

+38
-14
lines changed

elasticsearch-api/lib/elasticsearch/api/actions/index.rb

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
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+
118
module Elasticsearch
219
module API
320
module Actions
@@ -40,7 +57,7 @@ module Actions
4057
# client.cluster.put_settings body: { transient: { 'indices.ttl.interval' => '1s' } }
4158
#
4259
# # Enable the `_ttl` property for all types within the index
43-
# client.indices.create index: 'myindex', body: { mappings: { mytype: { _ttl: { enabled: true } } } }
60+
# client.indices.create index: 'myindex', body: { mappings: { properties: { _ttl: { enabled: true } } } }
4461
#
4562
# client.index index: 'myindex', type: 'mytype', id: '1', body: { title: 'TEST' }, ttl: '5s'
4663
#
@@ -50,53 +67,60 @@ module Actions
5067
# sleep 3 and client.get index: 'myindex', type: 'mytype', id: '1'
5168
# # => Elasticsearch::Transport::Transport::Errors::NotFound: [404] ...
5269
#
53-
# @option arguments [String] :id Document ID
70+
# @option arguments [String] :id Document ID (optional, will be auto-generated if missing)
5471
# @option arguments [String] :index The name of the index (*Required*)
5572
# @option arguments [String] :type The type of the document (*Required*)
56-
# @option arguments [Hash] :body The document (*Required*)
57-
# @option arguments [String] :wait_for_active_shards Sets the number of shard copies that must be active before proceeding with the index 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)
73+
# @option arguments [Hash] :body The document
74+
# @option arguments [String] :consistency Explicit write consistency setting for the operation
75+
# (options: one, quorum, all)
76+
# @option arguments [Boolean] :include_type_name Whether a type should be expected in the body of the mappings.
5877
# @option arguments [String] :op_type Explicit operation type (options: index, create)
5978
# @option arguments [String] :parent ID of the parent document
60-
# @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. (options: true, false, wait_for)
79+
# @option arguments [String] :percolate Percolator queries to execute while indexing the document
80+
# @option arguments [Boolean] :refresh Refresh the index after performing the operation
81+
# @option arguments [String] :replication Specific replication type (options: sync, async)
6182
# @option arguments [String] :routing Specific routing value
6283
# @option arguments [Time] :timeout Explicit operation timeout
84+
# @option arguments [Time] :timestamp Explicit timestamp for the document
85+
# @option arguments [Duration] :ttl Expiration time for the document
6386
# @option arguments [Number] :version Explicit version number for concurrency control
6487
# @option arguments [String] :version_type Specific version type (options: internal, external, external_gte, force)
65-
# @option arguments [Number] :if_seq_no only perform the index operation if the last operation that has changed the document has the specified sequence number
66-
# @option arguments [Number] :if_primary_term only perform the index operation if the last operation that has changed the document has the specified primary term
67-
# @option arguments [String] :pipeline The pipeline id to preprocess incoming documents with
6888
#
6989
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html
7090
#
7191
def index(arguments={})
7292
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
73-
raise ArgumentError, "Required argument 'type' missing" unless arguments[:type]
93+
arguments[:type] ||= DEFAULT_DOC
7494
method = arguments[:id] ? HTTP_PUT : HTTP_POST
7595
path = Utils.__pathify Utils.__escape(arguments[:index]),
7696
Utils.__escape(arguments[:type]),
7797
Utils.__escape(arguments[:id])
7898

7999
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
80100
body = arguments[:body]
81-
82101
perform_request(method, path, params, body).body
83102
end
84103

85104
# Register this action with its valid params when the module is loaded.
86105
#
87-
# @since 6.2.0
106+
# @since 6.1.1
88107
ParamsRegistry.register(:index, [
89-
:wait_for_active_shards,
108+
:consistency,
109+
:include_type_name,
90110
:op_type,
91111
:parent,
112+
:percolate,
113+
:pipeline,
92114
:refresh,
115+
:replication,
93116
:routing,
94117
:timeout,
118+
:timestamp,
119+
:ttl,
95120
:version,
96121
:version_type,
97122
:if_seq_no,
98-
:if_primary_term,
99-
:pipeline ].freeze)
123+
:if_primary_term ].freeze)
100124
end
101125
end
102126
end

0 commit comments

Comments
 (0)