Skip to content

Commit 6231009

Browse files
authored
Remove 2.x backward compatibility of mappings. (#21670)
For the record, I also had to remove the geo-hash cell and geo-distance range queries to make the code compile. These queries already throw an exception in all cases with 5.x indices, so that does not hurt any more. I also had to rename all 2.x bwc indices from `index-${version}` to `unsupported-${version}` to make `OldIndexBackwardCompatibilityIT` happy.
1 parent 235e6ac commit 6231009

File tree

279 files changed

+466
-24538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+466
-24538
lines changed

core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.elasticsearch.common.lucene.search.Queries;
4242
import org.elasticsearch.common.unit.Fuzziness;
4343
import org.elasticsearch.index.mapper.DateFieldMapper;
44-
import org.elasticsearch.index.mapper.LegacyDateFieldMapper;
4544
import org.elasticsearch.index.mapper.MappedFieldType;
4645
import org.elasticsearch.index.mapper.MapperService;
4746
import org.elasticsearch.index.mapper.StringFieldType;
@@ -336,11 +335,7 @@ private Query getRangeQuerySingle(String field, String part1, String part2,
336335
BytesRef part1Binary = part1 == null ? null : getAnalyzer().normalize(field, part1);
337336
BytesRef part2Binary = part2 == null ? null : getAnalyzer().normalize(field, part2);
338337
Query rangeQuery;
339-
if (currentFieldType instanceof LegacyDateFieldMapper.DateFieldType && settings.timeZone() != null) {
340-
LegacyDateFieldMapper.DateFieldType dateFieldType = (LegacyDateFieldMapper.DateFieldType) this.currentFieldType;
341-
rangeQuery = dateFieldType.rangeQuery(part1Binary, part2Binary,
342-
startInclusive, endInclusive, settings.timeZone(), null, context);
343-
} else if (currentFieldType instanceof DateFieldMapper.DateFieldType && settings.timeZone() != null) {
338+
if (currentFieldType instanceof DateFieldMapper.DateFieldType && settings.timeZone() != null) {
344339
DateFieldMapper.DateFieldType dateFieldType = (DateFieldMapper.DateFieldType) this.currentFieldType;
345340
rangeQuery = dateFieldType.rangeQuery(part1Binary, part2Binary,
346341
startInclusive, endInclusive, settings.timeZone(), null, context);

core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
305305
String parent = null;
306306
FetchSourceContext fetchSourceContext = defaultFetchSourceContext;
307307
String[] fields = defaultFields;
308-
String timestamp = null;
309-
TimeValue ttl = null;
310308
String opType = null;
311309
long version = Versions.MATCH_ANY;
312310
VersionType versionType = VersionType.INTERNAL;
@@ -336,14 +334,6 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
336334
routing = parser.text();
337335
} else if ("_parent".equals(currentFieldName) || "parent".equals(currentFieldName)) {
338336
parent = parser.text();
339-
} else if ("_timestamp".equals(currentFieldName) || "timestamp".equals(currentFieldName)) {
340-
timestamp = parser.text();
341-
} else if ("_ttl".equals(currentFieldName) || "ttl".equals(currentFieldName)) {
342-
if (parser.currentToken() == XContentParser.Token.VALUE_STRING) {
343-
ttl = TimeValue.parseTimeValue(parser.text(), null, currentFieldName);
344-
} else {
345-
ttl = new TimeValue(parser.longValue());
346-
}
347337
} else if ("op_type".equals(currentFieldName) || "opType".equals(currentFieldName)) {
348338
opType = parser.text();
349339
} else if ("_version".equals(currentFieldName) || "version".equals(currentFieldName)) {
@@ -394,15 +384,15 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
394384
// of index request.
395385
if ("index".equals(action)) {
396386
if (opType == null) {
397-
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).timestamp(timestamp).ttl(ttl).version(version).versionType(versionType)
387+
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).version(version).versionType(versionType)
398388
.setPipeline(pipeline).source(data.slice(from, nextMarker - from)), payload);
399389
} else {
400-
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).timestamp(timestamp).ttl(ttl).version(version).versionType(versionType)
390+
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).version(version).versionType(versionType)
401391
.create("create".equals(opType)).setPipeline(pipeline)
402392
.source(data.slice(from, nextMarker - from)), payload);
403393
}
404394
} else if ("create".equals(action)) {
405-
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).timestamp(timestamp).ttl(ttl).version(version).versionType(versionType)
395+
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).version(version).versionType(versionType)
406396
.create(true).setPipeline(pipeline)
407397
.source(data.slice(from, nextMarker - from)), payload);
408398
} else if ("update".equals(action)) {
@@ -420,15 +410,11 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
420410

421411
IndexRequest upsertRequest = updateRequest.upsertRequest();
422412
if (upsertRequest != null) {
423-
upsertRequest.timestamp(timestamp);
424-
upsertRequest.ttl(ttl);
425413
upsertRequest.version(version);
426414
upsertRequest.versionType(versionType);
427415
}
428416
IndexRequest doc = updateRequest.doc();
429417
if (doc != null) {
430-
doc.timestamp(timestamp);
431-
doc.ttl(ttl);
432418
doc.version(version);
433419
doc.versionType(versionType);
434420
}

core/src/main/java/org/elasticsearch/action/index/IndexRequest.java

Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
package org.elasticsearch.action.index;
2121

2222
import org.elasticsearch.ElasticsearchGenerationException;
23+
import org.elasticsearch.Version;
2324
import org.elasticsearch.action.ActionRequestValidationException;
2425
import org.elasticsearch.action.DocWriteRequest;
2526
import org.elasticsearch.action.RoutingMissingException;
26-
import org.elasticsearch.action.TimestampParsingException;
2727
import org.elasticsearch.action.support.replication.ReplicatedWriteRequest;
2828
import org.elasticsearch.client.Requests;
2929
import org.elasticsearch.cluster.metadata.MappingMetaData;
@@ -41,7 +41,6 @@
4141
import org.elasticsearch.common.xcontent.XContentHelper;
4242
import org.elasticsearch.common.xcontent.XContentType;
4343
import org.elasticsearch.index.VersionType;
44-
import org.elasticsearch.index.mapper.TimestampFieldMapper;
4544

4645
import java.io.IOException;
4746
import java.nio.charset.StandardCharsets;
@@ -75,10 +74,6 @@ public class IndexRequest extends ReplicatedWriteRequest<IndexRequest> implement
7574
private String routing;
7675
@Nullable
7776
private String parent;
78-
@Nullable
79-
private String timestamp;
80-
@Nullable
81-
private TimeValue ttl;
8277

8378
private BytesReference source;
8479

@@ -164,12 +159,6 @@ public ActionRequestValidationException validate() {
164159
validationException = addValidationError("version type [force] may no longer be used", validationException);
165160
}
166161

167-
if (ttl != null) {
168-
if (ttl.millis() < 0) {
169-
validationException = addValidationError("ttl must not be negative", validationException);
170-
}
171-
}
172-
173162
if (id != null && id.getBytes(StandardCharsets.UTF_8).length > 512) {
174163
validationException = addValidationError("id is too long, must be no longer than 512 bytes but was: " +
175164
id.getBytes(StandardCharsets.UTF_8).length, validationException);
@@ -265,49 +254,6 @@ public String parent() {
265254
return this.parent;
266255
}
267256

268-
/**
269-
* Sets the timestamp either as millis since the epoch, or, in the configured date format.
270-
*/
271-
public IndexRequest timestamp(String timestamp) {
272-
this.timestamp = timestamp;
273-
return this;
274-
}
275-
276-
public String timestamp() {
277-
return this.timestamp;
278-
}
279-
280-
/**
281-
* Sets the ttl value as a time value expression.
282-
*/
283-
public IndexRequest ttl(String ttl) {
284-
this.ttl = TimeValue.parseTimeValue(ttl, null, "ttl");
285-
return this;
286-
}
287-
288-
/**
289-
* Sets the ttl as a {@link TimeValue} instance.
290-
*/
291-
public IndexRequest ttl(TimeValue ttl) {
292-
this.ttl = ttl;
293-
return this;
294-
}
295-
296-
/**
297-
* Sets the relative ttl value in milliseconds. It musts be greater than 0 as it makes little sense otherwise.
298-
*/
299-
public IndexRequest ttl(long ttl) {
300-
this.ttl = new TimeValue(ttl);
301-
return this;
302-
}
303-
304-
/**
305-
* Returns the ttl as a {@link TimeValue}
306-
*/
307-
public TimeValue ttl() {
308-
return this.ttl;
309-
}
310-
311257
/**
312258
* Sets the ingest pipeline to be executed before indexing the document
313259
*/
@@ -537,11 +483,6 @@ public VersionType versionType() {
537483

538484

539485
public void process(@Nullable MappingMetaData mappingMd, boolean allowIdGeneration, String concreteIndex) {
540-
// resolve timestamp if provided externally
541-
if (timestamp != null) {
542-
timestamp = MappingMetaData.Timestamp.parseStringTimestamp(timestamp,
543-
mappingMd != null ? mappingMd.timestamp().dateTimeFormatter() : TimestampFieldMapper.Defaults.DATE_TIME_FORMATTER);
544-
}
545486
if (mappingMd != null) {
546487
// might as well check for routing here
547488
if (mappingMd.routing().required() && routing == null) {
@@ -563,30 +504,6 @@ public void process(@Nullable MappingMetaData mappingMd, boolean allowIdGenerati
563504
autoGeneratedTimestamp = Math.max(0, System.currentTimeMillis()); // extra paranoia
564505
id(UUIDs.base64UUID());
565506
}
566-
567-
// generate timestamp if not provided, we always have one post this stage...
568-
if (timestamp == null) {
569-
String defaultTimestamp = TimestampFieldMapper.Defaults.DEFAULT_TIMESTAMP;
570-
if (mappingMd != null && mappingMd.timestamp() != null) {
571-
// If we explicitly ask to reject null timestamp
572-
if (mappingMd.timestamp().ignoreMissing() != null && mappingMd.timestamp().ignoreMissing() == false) {
573-
throw new TimestampParsingException("timestamp is required by mapping");
574-
}
575-
defaultTimestamp = mappingMd.timestamp().defaultTimestamp();
576-
}
577-
578-
if (defaultTimestamp.equals(TimestampFieldMapper.Defaults.DEFAULT_TIMESTAMP)) {
579-
timestamp = Long.toString(System.currentTimeMillis());
580-
} else {
581-
// if we are here, the defaultTimestamp is not
582-
// TimestampFieldMapper.Defaults.DEFAULT_TIMESTAMP but
583-
// this can only happen if defaultTimestamp was
584-
// assigned again because mappingMd and
585-
// mappingMd#timestamp() are not null
586-
assert mappingMd != null;
587-
timestamp = MappingMetaData.Timestamp.parseStringTimestamp(defaultTimestamp, mappingMd.timestamp().dateTimeFormatter());
588-
}
589-
}
590507
}
591508

592509
/* resolve the routing if needed */
@@ -601,8 +518,10 @@ public void readFrom(StreamInput in) throws IOException {
601518
id = in.readOptionalString();
602519
routing = in.readOptionalString();
603520
parent = in.readOptionalString();
604-
timestamp = in.readOptionalString();
605-
ttl = in.readOptionalWriteable(TimeValue::new);
521+
if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) {
522+
in.readOptionalString(); // timestamp
523+
in.readOptionalWriteable(TimeValue::new); // ttl
524+
}
606525
source = in.readBytesReference();
607526
opType = OpType.fromId(in.readByte());
608527
version = in.readLong();
@@ -619,8 +538,10 @@ public void writeTo(StreamOutput out) throws IOException {
619538
out.writeOptionalString(id);
620539
out.writeOptionalString(routing);
621540
out.writeOptionalString(parent);
622-
out.writeOptionalString(timestamp);
623-
out.writeOptionalWriteable(ttl);
541+
if (out.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) {
542+
out.writeOptionalString(null);
543+
out.writeOptionalWriteable(null);
544+
}
624545
out.writeBytesReference(source);
625546
out.writeByte(opType.getId());
626547
out.writeLong(version);

core/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.elasticsearch.client.ElasticsearchClient;
2626
import org.elasticsearch.common.Nullable;
2727
import org.elasticsearch.common.bytes.BytesReference;
28-
import org.elasticsearch.common.unit.TimeValue;
2928
import org.elasticsearch.common.xcontent.XContentBuilder;
3029
import org.elasticsearch.common.xcontent.XContentType;
3130
import org.elasticsearch.index.VersionType;
@@ -231,38 +230,6 @@ public IndexRequestBuilder setVersionType(VersionType versionType) {
231230
return this;
232231
}
233232

234-
/**
235-
* Sets the timestamp either as millis since the epoch, or, in the configured date format.
236-
*/
237-
public IndexRequestBuilder setTimestamp(String timestamp) {
238-
request.timestamp(timestamp);
239-
return this;
240-
}
241-
242-
/**
243-
* Sets the ttl value as a time value expression.
244-
*/
245-
public IndexRequestBuilder setTTL(String ttl) {
246-
request.ttl(ttl);
247-
return this;
248-
}
249-
250-
/**
251-
* Sets the relative ttl value in milliseconds. It musts be greater than 0 as it makes little sense otherwise.
252-
*/
253-
public IndexRequestBuilder setTTL(long ttl) {
254-
request.ttl(ttl);
255-
return this;
256-
}
257-
258-
/**
259-
* Sets the ttl as a {@link TimeValue} instance.
260-
*/
261-
public IndexRequestBuilder setTTL(TimeValue ttl) {
262-
request.ttl(ttl);
263-
return this;
264-
}
265-
266233
/**
267234
* Sets the ingest pipeline to be executed before indexing the document
268235
*/

core/src/main/java/org/elasticsearch/action/index/TransportIndexAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected WriteReplicaResult shardOperationOnReplica(IndexRequest request, Index
171171
public static Engine.IndexResult executeIndexRequestOnReplica(IndexRequest request, IndexShard replica) {
172172
final ShardId shardId = replica.shardId();
173173
SourceToParse sourceToParse = SourceToParse.source(SourceToParse.Origin.REPLICA, shardId.getIndexName(), request.type(), request.id(), request.source())
174-
.routing(request.routing()).parent(request.parent()).timestamp(request.timestamp()).ttl(request.ttl());
174+
.routing(request.routing()).parent(request.parent());
175175

176176
final Engine.Index operation;
177177
try {
@@ -189,7 +189,7 @@ public static Engine.IndexResult executeIndexRequestOnReplica(IndexRequest reque
189189
/** Utility method to prepare an index operation on primary shards */
190190
static Engine.Index prepareIndexOperationOnPrimary(IndexRequest request, IndexShard primary) {
191191
SourceToParse sourceToParse = SourceToParse.source(SourceToParse.Origin.PRIMARY, request.index(), request.type(), request.id(), request.source())
192-
.routing(request.routing()).parent(request.parent()).timestamp(request.timestamp()).ttl(request.ttl());
192+
.routing(request.routing()).parent(request.parent());
193193
return primary.prepareIndexOnPrimary(sourceToParse, request.version(), request.versionType(), request.getAutoGeneratedTimestamp(), request.isRetry());
194194
}
195195

core/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ private static List<IngestDocument> parseDocs(Map<String, Object> config) {
156156
ConfigurationUtils.readStringProperty(null, null, dataMap, MetaData.ID.getFieldName(), "_id"),
157157
ConfigurationUtils.readOptionalStringProperty(null, null, dataMap, MetaData.ROUTING.getFieldName()),
158158
ConfigurationUtils.readOptionalStringProperty(null, null, dataMap, MetaData.PARENT.getFieldName()),
159-
ConfigurationUtils.readOptionalStringProperty(null, null, dataMap, MetaData.TIMESTAMP.getFieldName()),
160-
ConfigurationUtils.readOptionalStringProperty(null, null, dataMap, MetaData.TTL.getFieldName()),
161159
document);
162160
ingestDocumentList.add(ingestDocument);
163161
}

0 commit comments

Comments
 (0)