From fbcf40af5f0b14353b189aacdd31111ffda50588 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Fri, 17 May 2019 15:22:21 +0100 Subject: [PATCH 1/3] Removes type from TermVectors APIs --- .../client/core/TermVectorsResponse.java | 30 ++---- .../client/core/TermVectorsResponseTests.java | 8 +- .../documentation/CRUDDocumentationIT.java | 3 +- .../high-level/document/term-vectors.asciidoc | 7 +- docs/reference/docs/termvectors.asciidoc | 3 - .../AnnotatedTextFieldMapperTests.java | 2 +- .../rest-api-spec/test/mlt/20_docs.yml | 2 - .../rest-api-spec/test/mlt/30_unlike.yml | 2 - .../test/mtermvectors/20_deprecated.yml | 1 - .../test/termvectors/20_issue7121.yml | 1 - .../action/RoutingMissingException.java | 5 + .../MultiTermVectorsItemResponse.java | 10 -- .../termvectors/MultiTermVectorsRequest.java | 8 +- .../MultiTermVectorsRequestBuilder.java | 9 +- .../termvectors/MultiTermVectorsResponse.java | 29 +++--- .../termvectors/TermVectorsRequest.java | 60 +++--------- .../TermVectorsRequestBuilder.java | 12 +-- .../termvectors/TermVectorsResponse.java | 22 ++--- .../TransportMultiTermVectorsAction.java | 9 +- .../TransportShardMultiTermsVectorAction.java | 6 +- .../TransportTermVectorsAction.java | 2 +- .../java/org/elasticsearch/client/Client.java | 3 +- .../client/support/AbstractClient.java | 4 +- .../index/query/MoreLikeThisQueryBuilder.java | 97 +++---------------- .../index/termvectors/TermVectorsService.java | 15 ++- .../document/RestMultiTermVectorsAction.java | 4 - .../document/RestTermVectorsAction.java | 3 +- .../action/IndicesRequestIT.java | 4 +- .../AbstractTermVectorsTestCase.java | 2 +- .../action/termvectors/GetTermVectorsIT.java | 55 +++++------ .../termvectors/GetTermVectorsTests.java | 2 +- .../termvectors/MultiTermVectorsIT.java | 26 ++--- .../termvectors/TermVectorsUnitTests.java | 18 ++-- .../TransportMultiTermVectorsActionTests.java | 8 +- .../query/MoreLikeThisQueryBuilderTests.java | 20 +--- .../termvectors/TermVectorsServiceTests.java | 22 ++--- .../routing/SimpleRoutingIT.java | 13 ++- .../search/fetch/FetchSubPhasePluginIT.java | 2 +- .../search/morelikethis/MoreLikeThisIT.java | 42 ++++---- .../validate/SimpleValidateQueryIT.java | 2 +- .../action/termvectors/multiRequest1.json | 3 +- .../action/termvectors/multiRequest2.json | 6 +- .../action/termvectors/multiRequest3.json | 1 - .../index/engine/FrozenIndexTests.java | 2 +- .../DocumentLevelSecurityTests.java | 27 +++--- .../integration/FieldLevelSecurityTests.java | 32 +++--- .../authz/AuthorizationServiceTests.java | 10 +- .../security/authz/ReadActionsTests.java | 8 +- 48 files changed, 239 insertions(+), 423 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/TermVectorsResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/TermVectorsResponse.java index eef76ed7cb043..8f4232cca6e2c 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/TermVectorsResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/TermVectorsResponse.java @@ -33,17 +33,14 @@ public class TermVectorsResponse { private final String index; - private final String type; private final String id; private final long docVersion; private final boolean found; private final long tookInMillis; private final List termVectorList; - public TermVectorsResponse( - String index, String type, String id, long version, boolean found, long tookInMillis, List termVectorList) { + public TermVectorsResponse(String index, String id, long version, boolean found, long tookInMillis, List termVectorList) { this.index = index; - this.type = type; this.id = id; this.docVersion = version; this.found = found; @@ -53,18 +50,17 @@ public TermVectorsResponse( private static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("term_vectors", true, args -> { - // as the response comes from server, we are sure that args[6] will be a list of TermVector - @SuppressWarnings("unchecked") List termVectorList = (List) args[6]; + // as the response comes from server, we are sure that args[5] will be a list of TermVector + @SuppressWarnings("unchecked") List termVectorList = (List) args[5]; if (termVectorList != null) { Collections.sort(termVectorList, Comparator.comparing(TermVector::getFieldName)); } return new TermVectorsResponse( (String) args[0], (String) args[1], - (String) args[2], - (long) args[3], - (boolean) args[4], - (long) args[5], + (long) args[2], + (boolean) args[3], + (long) args[4], termVectorList ); } @@ -72,7 +68,6 @@ public TermVectorsResponse( static { PARSER.declareString(constructorArg(), new ParseField("_index")); - PARSER.declareString(constructorArg(), new ParseField("_type")); PARSER.declareString(optionalConstructorArg(), new ParseField("_id")); PARSER.declareLong(constructorArg(), new ParseField("_version")); PARSER.declareBoolean(constructorArg(), new ParseField("found")); @@ -92,16 +87,6 @@ public String getIndex() { return index; } - /** - * Returns the type for the response - * - * @deprecated Types are in the process of being removed. - */ - @Deprecated - public String getType() { - return type; - } - /** * Returns the id of the request * can be NULL if there is no document ID @@ -145,7 +130,6 @@ public boolean equals(Object obj) { if (!(obj instanceof TermVectorsResponse)) return false; TermVectorsResponse other = (TermVectorsResponse) obj; return index.equals(other.index) - && type.equals(other.type) && Objects.equals(id, other.id) && docVersion == other.docVersion && found == other.found @@ -155,7 +139,7 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return Objects.hash(index, type, id, docVersion, found, tookInMillis, termVectorList); + return Objects.hash(index, id, docVersion, found, tookInMillis, termVectorList); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/core/TermVectorsResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/core/TermVectorsResponseTests.java index 714a7269a19d9..debe08879339d 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/core/TermVectorsResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/core/TermVectorsResponseTests.java @@ -22,11 +22,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.test.ESTestCase; -import java.util.ArrayList; -import java.util.List; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.List; import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; @@ -47,7 +47,6 @@ public void testFromXContent() throws IOException { static void toXContent(TermVectorsResponse response, XContentBuilder builder) throws IOException { builder.startObject(); builder.field("_index", response.getIndex()); - builder.field("_type", response.getType()); if (response.getId() != null) { builder.field("_id", response.getId()); } @@ -119,7 +118,6 @@ private static void toXContent(TermVectorsResponse.TermVector tv, XContentBuilde static TermVectorsResponse createTestInstance() { String index = randomAlphaOfLength(5); - String type = randomAlphaOfLength(5); String id = String.valueOf(randomIntBetween(1,100)); long version = randomNonNegativeLong(); long tookInMillis = randomNonNegativeLong(); @@ -142,7 +140,7 @@ static TermVectorsResponse createTestInstance() { fieldName, hasFieldStatistics, hasTermStatistics, hasScores, hasOffsets, hasPositions, hasPayloads)); } } - TermVectorsResponse tvresponse = new TermVectorsResponse(index, type, id, version, found, tookInMillis, tvList); + TermVectorsResponse tvresponse = new TermVectorsResponse(index, id, version, found, tookInMillis, tvList); return tvresponse; } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java index fe003d691a830..d430d05b7ea2b 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java @@ -703,7 +703,7 @@ public void testBulk() throws Exception { request.add(new IndexRequest("posts").id("4") // <3> .source(XContentType.JSON,"field", "baz")); // end::bulk-request-with-mixed-operations - BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); + BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); assertSame(RestStatus.OK, bulkResponse.status()); assertFalse(bulkResponse.hasFailures()); @@ -1614,7 +1614,6 @@ public void testTermVectors() throws Exception { // tag::term-vectors-response String index = response.getIndex(); // <1> - String type = response.getType(); // <2> String id = response.getId(); // <3> boolean found = response.getFound(); // <4> // end::term-vectors-response diff --git a/docs/java-rest/high-level/document/term-vectors.asciidoc b/docs/java-rest/high-level/document/term-vectors.asciidoc index e8d4a25a2cac0..36c7553d4885e 100644 --- a/docs/java-rest/high-level/document/term-vectors.asciidoc +++ b/docs/java-rest/high-level/document/term-vectors.asciidoc @@ -15,7 +15,7 @@ artificially provided by the user. [id="{upid}-{api}-request"] ==== Term Vectors Request -A +{request}+ expects an `index`, a `type` and an `id` to specify +A +{request}+ expects an `index` and an `id` to specify a certain document, and fields for which the information is retrieved. ["source","java",subs="attributes,callouts,macros"] @@ -71,9 +71,8 @@ include::../execution.asciidoc[] include-tagged::{doc-tests-file}[{api}-response] -------------------------------------------------- <1> The index name of the document. -<2> The type name of the document. -<3> The id of the document. -<4> Indicates whether or not the document found. +<2> The id of the document. +<3> Indicates whether or not the document found. ===== Inspecting Term Vectors diff --git a/docs/reference/docs/termvectors.asciidoc b/docs/reference/docs/termvectors.asciidoc index 1e2748916005c..8ec4019fe8861 100644 --- a/docs/reference/docs/termvectors.asciidoc +++ b/docs/reference/docs/termvectors.asciidoc @@ -207,7 +207,6 @@ Response: { "_id": "1", "_index": "twitter", - "_type": "_doc", "_version": 1, "found": true, "took": 6, @@ -344,7 +343,6 @@ Response: -------------------------------------------------- { "_index": "twitter", - "_type": "_doc", "_version": 0, "found": true, "took": 6, @@ -415,7 +413,6 @@ Response: -------------------------------------------------- { "_index": "imdb", - "_type": "_doc", "_version": 0, "found": true, "term_vectors": { diff --git a/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java b/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java index aa0dbe07c8305..969d91c2d6b5d 100644 --- a/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java +++ b/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java @@ -226,7 +226,7 @@ public void testAgainstTermVectorsAPI() throws IOException { } bulk.get(); - TermVectorsRequest request = new TermVectorsRequest("test", "type", "0").termStatistics(true); + TermVectorsRequest request = new TermVectorsRequest("test", "0").termStatistics(true); IndicesService indicesService = getInstanceFromNode(IndicesService.class); IndexService test = indicesService.indexService(resolveIndex("test")); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/20_docs.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/20_docs.yml index bb1b25a0dcb40..50eb344d99048 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/20_docs.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/20_docs.yml @@ -41,12 +41,10 @@ like: - _index: test_1 - _type: _doc doc: foo: bar - _index: test_1 - _type: _doc _id: 2 - _id: 3 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/30_unlike.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/30_unlike.yml index abea4c8fbe57a..a0f96eb6b2d1f 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/30_unlike.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/mlt/30_unlike.yml @@ -40,11 +40,9 @@ more_like_this: like: _index: test_1 - _type: _doc _id: 1 unlike: _index: test_1 - _type: _doc _id: 3 include: true min_doc_freq: 0 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/mtermvectors/20_deprecated.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/mtermvectors/20_deprecated.yml index db8e566f4b613..8c058deff841c 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/mtermvectors/20_deprecated.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/mtermvectors/20_deprecated.yml @@ -40,7 +40,6 @@ "docs": - "_index" : "testidx" - "_type" : "_doc" "_id" : "testing_document" "version" : 1 "_version_type" : "external" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/termvectors/20_issue7121.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/termvectors/20_issue7121.yml index eb7d335c28c60..e3ba834de074f 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/termvectors/20_issue7121.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/termvectors/20_issue7121.yml @@ -33,6 +33,5 @@ realtime: false - match: { _index: "testidx" } - - match: { _type: "_doc" } - match: { _id: "1" } - is_false: found diff --git a/server/src/main/java/org/elasticsearch/action/RoutingMissingException.java b/server/src/main/java/org/elasticsearch/action/RoutingMissingException.java index 1ecd9593e1c36..e3ef791814ac8 100644 --- a/server/src/main/java/org/elasticsearch/action/RoutingMissingException.java +++ b/server/src/main/java/org/elasticsearch/action/RoutingMissingException.java @@ -22,6 +22,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -33,6 +34,10 @@ public class RoutingMissingException extends ElasticsearchException { private final String id; + public RoutingMissingException(String index, String id) { + this(index, MapperService.SINGLE_MAPPING_NAME, id); + } + public RoutingMissingException(String index, String type, String id) { super("routing is required for [" + index + "]/[" + type + "]/[" + id + "]"); Objects.requireNonNull(index, "index must not be null"); diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsItemResponse.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsItemResponse.java index 14ac59cb132bd..9cacf166952fb 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsItemResponse.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsItemResponse.java @@ -53,16 +53,6 @@ public String getIndex() { return response.getIndex(); } - /** - * The type of the document. - */ - public String getType() { - if (failure != null) { - return failure.getType(); - } - return response.getType(); - } - /** * The id of the document. */ diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java index 5f869e2ac7235..4b2a3bd2fe6a5 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.mapper.MapperService; import java.io.IOException; import java.util.ArrayList; @@ -52,8 +51,8 @@ public MultiTermVectorsRequest add(TermVectorsRequest termVectorsRequest) { return this; } - public MultiTermVectorsRequest add(String index, @Nullable String type, String id) { - requests.add(new TermVectorsRequest(index, type, id)); + public MultiTermVectorsRequest add(String index, String id) { + requests.add(new TermVectorsRequest(index, id)); return this; } @@ -102,9 +101,6 @@ public void add(TermVectorsRequest template, @Nullable XContentParser parser) th throw new IllegalArgumentException("docs array element should include an object"); } TermVectorsRequest termVectorsRequest = new TermVectorsRequest(template); - if (termVectorsRequest.type() == null) { - termVectorsRequest.type(MapperService.SINGLE_MAPPING_NAME); - } TermVectorsRequest.parseRequest(termVectorsRequest, parser); add(termVectorsRequest); } diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequestBuilder.java index b982c4f720930..7d0d1c781ec75 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequestBuilder.java @@ -21,7 +21,6 @@ import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.common.Nullable; public class MultiTermVectorsRequestBuilder extends ActionRequestBuilder { @@ -29,16 +28,16 @@ public MultiTermVectorsRequestBuilder(ElasticsearchClient client, MultiTermVecto super(client, action, new MultiTermVectorsRequest()); } - public MultiTermVectorsRequestBuilder add(String index, @Nullable String type, Iterable ids) { + public MultiTermVectorsRequestBuilder add(String index, Iterable ids) { for (String id : ids) { - request.add(index, type, id); + request.add(index, id); } return this; } - public MultiTermVectorsRequestBuilder add(String index, @Nullable String type, String... ids) { + public MultiTermVectorsRequestBuilder add(String index, String... ids) { for (String id : ids) { - request.add(index, type, id); + request.add(index, id); } return this; } diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java index 97a2007410edd..2264958422ad1 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.termvectors; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -38,7 +39,6 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable */ public static class Failure implements Streamable { private String index; - private String type; private String id; private Exception cause; @@ -46,9 +46,8 @@ public static class Failure implements Streamable { } - public Failure(String index, String type, String id, Exception cause) { + public Failure(String index, String id, Exception cause) { this.index = index; - this.type = type; this.id = id; this.cause = cause; } @@ -60,16 +59,6 @@ public String getIndex() { return this.index; } - /** - * The type of the action. - * - * @deprecated Types are in the process of being removed. - */ - @Deprecated - public String getType() { - return type; - } - /** * The id of the action. */ @@ -93,7 +82,13 @@ public static Failure readFailure(StreamInput in) throws IOException { @Override public void readFrom(StreamInput in) throws IOException { index = in.readString(); - type = in.readOptionalString(); + if (in.getVersion().before(Version.V_8_0_0)) { + // types no longer relevant so ignore + String type = in.readOptionalString(); + if (type != null) { + throw new IllegalStateException("types are no longer supported but found [" + type + "]"); + } + } id = in.readString(); cause = in.readException(); } @@ -101,7 +96,10 @@ public void readFrom(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(index); - out.writeOptionalString(type); + if (out.getVersion().before(Version.V_8_0_0)) { + // types not supported so send an empty array to previous versions + out.writeOptionalString(null); + } out.writeString(id); out.writeException(cause); } @@ -134,7 +132,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject(); Failure failure = response.getFailure(); builder.field(Fields._INDEX, failure.getIndex()); - builder.field(Fields._TYPE, failure.getType()); builder.field(Fields._ID, failure.getId()); ElasticsearchException.generateFailureXContent(builder, params, failure.getCause(), true); builder.endObject(); diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java index 0206ef3def02d..317dfd65d6b18 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java @@ -19,8 +19,8 @@ package org.elasticsearch.action.termvectors; -import org.apache.logging.log4j.LogManager; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.RealtimeRequest; import org.elasticsearch.action.ValidateActions; @@ -31,7 +31,6 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -39,7 +38,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.VersionType; -import org.elasticsearch.rest.action.document.RestTermVectorsAction; import java.io.IOException; import java.util.ArrayList; @@ -54,18 +52,13 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; /** - * Request returning the term vector (doc frequency, positions, offsets) for a - * document. + * Request returning the term vector (doc frequency, positions, offsets) for a document. *

- * Note, the {@link #index()}, {@link #type(String)} and {@link #id(String)} are - * required. + * Note, the {@link #index()} and {@link #id(String)} are required. */ public class TermVectorsRequest extends SingleShardRequest implements RealtimeRequest { - private static final DeprecationLogger deprecationLogger = new DeprecationLogger( - LogManager.getLogger(TermVectorsRequest.class)); private static final ParseField INDEX = new ParseField("_index"); - private static final ParseField TYPE = new ParseField("_type"); private static final ParseField ID = new ParseField("_id"); private static final ParseField ROUTING = new ParseField("routing"); private static final ParseField VERSION = new ParseField("version"); @@ -79,8 +72,6 @@ public class TermVectorsRequest extends SingleShardRequest i private static final ParseField DOC = new ParseField("doc"); - private String type; - private String id; private BytesReference doc; @@ -144,24 +135,22 @@ public TermVectorsRequest() { /** * Constructs a new term vector request for a document that will be fetch - * from the provided index. Use {@link #type(String)} and - * {@link #id(String)} to specify the document to load. + * from the provided index. Use and {@link #id(String)} to specify the + * document to load. */ - public TermVectorsRequest(String index, String type, String id) { + public TermVectorsRequest(String index, String id) { super(index); this.id = id; - this.type = type; } /** * Constructs a new term vector request for a document that will be fetch - * from the provided index. Use {@link #type(String)} and - * {@link #id(String)} to specify the document to load. + * from the provided index. Use {@link #id(String)} to specify the + * document to load. */ public TermVectorsRequest(TermVectorsRequest other) { super(other.index()); this.id = other.id(); - this.type = other.type(); if (other.doc != null) { this.doc = new BytesArray(other.doc().toBytesRef(), true); this.xContentType = other.xContentType; @@ -184,7 +173,6 @@ public TermVectorsRequest(TermVectorsRequest other) { public TermVectorsRequest(MultiGetRequest.Item item) { super(item.index()); this.id = item.id(); - this.type = item.type(); this.selectedFields(item.storedFields()); this.routing(item.routing()); } @@ -193,21 +181,6 @@ public EnumSet getFlags() { return flagsEnum; } - /** - * Sets the type of document to get the term vector for. - */ - public TermVectorsRequest type(String type) { - this.type = type; - return this; - } - - /** - * Returns the type of document to get the term vector for. - */ - public String type() { - return type; - } - /** * Returns the id of document the term vector is requested for. */ @@ -461,9 +434,6 @@ private void setFlag(Flag flag, boolean set) { @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validateNonNullIndex(); - if (type == null) { - validationException = ValidateActions.addValidationError("type is missing", validationException); - } if (id == null && doc == null) { validationException = ValidateActions.addValidationError("id or doc is missing", validationException); } @@ -480,7 +450,10 @@ public static TermVectorsRequest readTermVectorsRequest(StreamInput in) throws I @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - type = in.readString(); + if (in.getVersion().before(Version.V_8_0_0)) { + // types no longer relevant so ignore + in.readString(); + } id = in.readString(); if (in.readBoolean()) { @@ -519,7 +492,10 @@ public void readFrom(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeString(type); + if (out.getVersion().before(Version.V_8_0_0)) { + // types not supported so send an empty array to previous versions + out.writeString(null); + } out.writeString(id); out.writeBoolean(doc != null); @@ -599,10 +575,6 @@ public static void parseRequest(TermVectorsRequest termVectorsRequest, XContentP } else if (INDEX.match(currentFieldName, parser.getDeprecationHandler())) { // the following is important for multi request parsing. termVectorsRequest.index = parser.text(); - } else if (TYPE.match(currentFieldName, parser.getDeprecationHandler())) { - termVectorsRequest.type = parser.text(); - deprecationLogger.deprecatedAndMaybeLog("termvectors_with_types", - RestTermVectorsAction.TYPES_DEPRECATION_MESSAGE); } else if (ID.match(currentFieldName, parser.getDeprecationHandler())) { if (termVectorsRequest.doc != null) { throw new ElasticsearchParseException("failed to parse term vectors request. " + diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequestBuilder.java index 80bf769b9714e..7bdf46bf08cba 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequestBuilder.java @@ -44,8 +44,8 @@ public TermVectorsRequestBuilder(ElasticsearchClient client, TermVectorsAction a * from the provided index. Use {@code index}, {@code type} and * {@code id} to specify the document to load. */ - public TermVectorsRequestBuilder(ElasticsearchClient client, TermVectorsAction action, String index, String type, String id) { - super(client, action, new TermVectorsRequest(index, type, id)); + public TermVectorsRequestBuilder(ElasticsearchClient client, TermVectorsAction action, String index, String id) { + super(client, action, new TermVectorsRequest(index, id)); } /** @@ -56,14 +56,6 @@ public TermVectorsRequestBuilder setIndex(String index) { return this; } - /** - * Sets the type of the document. - */ - public TermVectorsRequestBuilder setType(String type) { - request.type(type); - return this; - } - /** * Sets the id of the document. */ diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsResponse.java b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsResponse.java index 3d0fb75f8d3eb..2cd1e3cccd7e5 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsResponse.java @@ -27,6 +27,7 @@ import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRefBuilder; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.termvectors.TermVectorsRequest.Flag; import org.elasticsearch.common.Nullable; @@ -38,6 +39,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.search.dfs.AggregatedDfs; import java.io.IOException; @@ -79,7 +81,6 @@ private static class FieldStrings { private BytesReference termVectors; private BytesReference headerRef; private String index; - private String type; private String id; private long docVersion; private boolean exists = false; @@ -94,9 +95,8 @@ private static class FieldStrings { int[] currentEndOffset = new int[0]; BytesReference[] currentPayloads = new BytesReference[0]; - public TermVectorsResponse(String index, String type, String id) { + public TermVectorsResponse(String index, String id) { this.index = index; - this.type = type; this.id = id; } @@ -105,7 +105,10 @@ public TermVectorsResponse(String index, String type, String id) { TermVectorsResponse(StreamInput in) throws IOException { index = in.readString(); - type = in.readString(); + if (in.getVersion().before(Version.V_8_0_0)) { + // types no longer relevant so ignore + in.readString(); + } id = in.readString(); docVersion = in.readVLong(); exists = in.readBoolean(); @@ -120,7 +123,10 @@ public TermVectorsResponse(String index, String type, String id) { @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(index); - out.writeString(type); + if (out.getVersion().before(Version.V_8_0_0)) { + // types not supported so send an empty array to previous versions + out.writeString(MapperService.SINGLE_MAPPING_NAME); + } out.writeString(id); out.writeVLong(docVersion); final boolean docExists = isExists(); @@ -176,11 +182,9 @@ public int size() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { assert index != null; - assert type != null; assert id != null; builder.startObject(); builder.field(FieldStrings._INDEX, index); - builder.field(FieldStrings._TYPE, type); if (!isArtificial()) { builder.field(FieldStrings._ID, id); } @@ -391,10 +395,6 @@ public String getIndex() { return index; } - public String getType() { - return type; - } - public String getId() { return id; } diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsAction.java b/server/src/main/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsAction.java index 20514733aff31..1d05c760b1e3b 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsAction.java @@ -69,7 +69,7 @@ protected void doExecute(Task task, final MultiTermVectorsRequest request, final termVectorsRequest.index())); if (!clusterState.metaData().hasConcreteIndex(termVectorsRequest.index())) { responses.set(i, new MultiTermVectorsItemResponse(null, - new MultiTermVectorsResponse.Failure(termVectorsRequest.index(), termVectorsRequest.type(), termVectorsRequest.id(), + new MultiTermVectorsResponse.Failure(termVectorsRequest.index(), termVectorsRequest.id(), new IndexNotFoundException(termVectorsRequest.index())))); continue; } @@ -77,8 +77,8 @@ protected void doExecute(Task task, final MultiTermVectorsRequest request, final if (termVectorsRequest.routing() == null && clusterState.getMetaData().routingRequired(concreteSingleIndex)) { responses.set(i, new MultiTermVectorsItemResponse(null, - new MultiTermVectorsResponse.Failure(concreteSingleIndex, termVectorsRequest.type(), termVectorsRequest.id(), - new RoutingMissingException(concreteSingleIndex, termVectorsRequest.type(), termVectorsRequest.id())))); + new MultiTermVectorsResponse.Failure(concreteSingleIndex, termVectorsRequest.id(), + new RoutingMissingException(concreteSingleIndex, termVectorsRequest.id())))); continue; } ShardId shardId = clusterService.operationRouting().shardId(clusterState, concreteSingleIndex, @@ -124,8 +124,7 @@ public void onFailure(Exception e) { for (int i = 0; i < shardRequest.locations.size(); i++) { TermVectorsRequest termVectorsRequest = shardRequest.requests.get(i); responses.set(shardRequest.locations.get(i), new MultiTermVectorsItemResponse(null, - new MultiTermVectorsResponse.Failure(shardRequest.index(), termVectorsRequest.type(), - termVectorsRequest.id(), e))); + new MultiTermVectorsResponse.Failure(shardRequest.index(), termVectorsRequest.id(), e))); } if (counter.decrementAndGet() == 0) { finishHim(); diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TransportShardMultiTermsVectorAction.java b/server/src/main/java/org/elasticsearch/action/termvectors/TransportShardMultiTermsVectorAction.java index 0292757121eff..d7ef6d262bcce 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TransportShardMultiTermsVectorAction.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TransportShardMultiTermsVectorAction.java @@ -88,10 +88,10 @@ protected MultiTermVectorsShardResponse shardOperation(MultiTermVectorsShardRequ if (TransportActions.isShardNotAvailableException(e)) { throw e; } else { - logger.debug(() -> new ParameterizedMessage("{} failed to execute multi term vectors for [{}]/[{}]", - shardId, termVectorsRequest.type(), termVectorsRequest.id()), e); + logger.debug(() -> new ParameterizedMessage("{} failed to execute multi term vectors for [{}]", shardId, + termVectorsRequest.id()), e); response.add(request.locations.get(i), - new MultiTermVectorsResponse.Failure(request.index(), termVectorsRequest.type(), termVectorsRequest.id(), e)); + new MultiTermVectorsResponse.Failure(request.index(), termVectorsRequest.id(), e)); } } } diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TransportTermVectorsAction.java b/server/src/main/java/org/elasticsearch/action/termvectors/TransportTermVectorsAction.java index 0e212ab7cce2f..48ff18cb49b18 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TransportTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TransportTermVectorsAction.java @@ -81,7 +81,7 @@ protected void resolveRequest(ClusterState state, InternalRequest request) { request.request().routing(state.metaData().resolveIndexRouting(request.request().routing(), request.request().index())); // Fail fast on the node that received the request. if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex())) { - throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id()); + throw new RoutingMissingException(request.concreteIndex(), request.request().id()); } } diff --git a/server/src/main/java/org/elasticsearch/client/Client.java b/server/src/main/java/org/elasticsearch/client/Client.java index 07871709f5726..bff8569c3c2fe 100644 --- a/server/src/main/java/org/elasticsearch/client/Client.java +++ b/server/src/main/java/org/elasticsearch/client/Client.java @@ -365,10 +365,9 @@ public interface Client extends ElasticsearchClient, Releasable { * Builder for the term vector request. * * @param index The index to load the document from - * @param type The type of the document * @param id The id of the document */ - TermVectorsRequestBuilder prepareTermVectors(String index, String type, String id); + TermVectorsRequestBuilder prepareTermVectors(String index, String id); /** * Multi get term vectors. diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 5c4c7ad44c6d2..0c81278fe490d 100644 --- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -576,8 +576,8 @@ public TermVectorsRequestBuilder prepareTermVectors() { } @Override - public TermVectorsRequestBuilder prepareTermVectors(String index, String type, String id) { - return new TermVectorsRequestBuilder(this, TermVectorsAction.INSTANCE, index, type, id); + public TermVectorsRequestBuilder prepareTermVectors(String index, String id) { + return new TermVectorsRequestBuilder(this, TermVectorsAction.INSTANCE, index, id); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index 11530ce5f30b3..0d71829830b85 100644 --- a/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -27,6 +27,7 @@ import org.apache.lucene.search.Query; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.Version; import org.elasticsearch.action.RoutingMissingException; import org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse; import org.elasticsearch.action.termvectors.MultiTermVectorsRequest; @@ -55,7 +56,6 @@ import org.elasticsearch.index.mapper.IdFieldMapper; import org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType; import org.elasticsearch.index.mapper.MappedFieldType; -import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.TextFieldMapper.TextFieldType; import java.io.IOException; @@ -69,7 +69,6 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.stream.Stream; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; @@ -117,7 +116,6 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder item.type == null); - } - private static void parseLikeField(XContentParser parser, List texts, List items) throws IOException { if (parser.currentToken().isValue()) { texts.add(parser.text()); @@ -1132,9 +1066,6 @@ private static void setDefaultIndexTypeFields(QueryShardContext context, Item it if (item.index() == null) { item.index(context.index().getName()); } - if (item.type() == null) { - item.type(MapperService.SINGLE_MAPPING_NAME); - } // default fields if not present but don't override for artificial docs if ((item.fields() == null || item.fields().length == 0) && item.doc() == null) { if (useDefaultField) { diff --git a/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java b/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java index b53c3d8da427c..e5809460c0400 100644 --- a/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java +++ b/server/src/main/java/org/elasticsearch/index/termvectors/TermVectorsService.java @@ -80,8 +80,7 @@ public static TermVectorsResponse getTermVectors(IndexShard indexShard, TermVect static TermVectorsResponse getTermVectors(IndexShard indexShard, TermVectorsRequest request, LongSupplier nanoTimeSupplier) { final long startTime = nanoTimeSupplier.getAsLong(); - final TermVectorsResponse termVectorsResponse = new TermVectorsResponse(indexShard.shardId().getIndex().getName(), - request.type(), request.id()); + final TermVectorsResponse termVectorsResponse = new TermVectorsResponse(indexShard.shardId().getIndex().getName(), request.id()); final Term uidTerm = new Term(IdFieldMapper.NAME, Uid.encodeId(request.id())); Fields termVectorsByField = null; @@ -93,7 +92,7 @@ static TermVectorsResponse getTermVectors(IndexShard indexShard, TermVectorsRequ handleFieldWildcards(indexShard, request); } - try (Engine.GetResult get = indexShard.get(new Engine.Get(request.realtime(), false, request.type(), + try (Engine.GetResult get = indexShard.get(new Engine.Get(request.realtime(), false, MapperService.SINGLE_MAPPING_NAME, request.id(), uidTerm) .version(request.version()).versionType(request.versionType())); Engine.Searcher searcher = indexShard.acquireSearcher("term_vector")) { @@ -215,7 +214,7 @@ private static Fields addGeneratedTermVectors(IndexShard indexShard, Engine.GetR String[] getFields = validFields.toArray(new String[validFields.size() + 1]); getFields[getFields.length - 1] = SourceFieldMapper.NAME; GetResult getResult = indexShard.getService().get( - get, request.id(), request.type(), getFields, null); + get, request.id(), MapperService.SINGLE_MAPPING_NAME, getFields, null); Fields generatedTermVectors = generateTermVectors(indexShard, getResult.sourceAsMap(), getResult.getFields().values(), request.offsets(), request.perFieldAnalyzer(), validFields); @@ -295,7 +294,7 @@ private static Fields generateTermVectors(IndexShard indexShard, private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVectorsRequest request) throws IOException { // parse the document, at the moment we do update the mapping, just like percolate - ParsedDocument parsedDocument = parseDocument(indexShard, indexShard.shardId().getIndexName(), request.type(), request.doc(), + ParsedDocument parsedDocument = parseDocument(indexShard, indexShard.shardId().getIndexName(), request.doc(), request.xContentType(), request.routing()); // select the right fields and generate term vectors @@ -324,12 +323,12 @@ private static Fields generateTermVectorsFromDoc(IndexShard indexShard, TermVect request.offsets(), request.perFieldAnalyzer(), seenFields); } - private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc, + private static ParsedDocument parseDocument(IndexShard indexShard, String index, BytesReference doc, XContentType xContentType, String routing) { MapperService mapperService = indexShard.mapperService(); - DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type); + DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(MapperService.SINGLE_MAPPING_NAME); ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse( - new SourceToParse(index, type, "_id_for_tv_api", doc, xContentType, routing)); + new SourceToParse(index, MapperService.SINGLE_MAPPING_NAME, "_id_for_tv_api", doc, xContentType, routing)); if (docMapper.getMapping() != null) { parsedDocument.addDynamicMappingsUpdate(docMapper.getMapping()); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java index 075167e97ccb2..1896314aa4a06 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java @@ -24,7 +24,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -56,9 +55,6 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC TermVectorsRequest template = new TermVectorsRequest() .index(request.param("index")); - - template.type(MapperService.SINGLE_MAPPING_NAME); - RestTermVectorsAction.readURIParameters(template, request); multiTermVectorsRequest.ids(Strings.commaDelimitedListToStringArray(request.param("ids"))); request.withContentOrSourceParamParserOrNull(p -> multiTermVectorsRequest.add(template, p)); diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java index 3e136b368280d..2a77a2b1afe19 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.VersionType; -import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -63,7 +62,7 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { TermVectorsRequest termVectorsRequest; - termVectorsRequest = new TermVectorsRequest(request.param("index"), MapperService.SINGLE_MAPPING_NAME, request.param("id")); + termVectorsRequest = new TermVectorsRequest(request.param("index"), request.param("id")); if (request.hasContentOrSourceParam()) { try (XContentParser parser = request.contentOrSourceParamParser()) { diff --git a/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java b/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java index cb5bad021eae9..24e2e68ed4fc6 100644 --- a/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java +++ b/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java @@ -340,7 +340,7 @@ public void testTermVector() { String termVectorShardAction = TermVectorsAction.NAME + "[s]"; interceptTransportActions(termVectorShardAction); - TermVectorsRequest termVectorsRequest = new TermVectorsRequest(randomIndexOrAlias(), "type", "id"); + TermVectorsRequest termVectorsRequest = new TermVectorsRequest(randomIndexOrAlias(), "id"); internalCluster().coordOnlyNodeClient().termVectors(termVectorsRequest).actionGet(); clearInterceptedActions(); @@ -356,7 +356,7 @@ public void testMultiTermVector() { int numDocs = iterations(1, 30); for (int i = 0; i < numDocs; i++) { String indexOrAlias = randomIndexOrAlias(); - multiTermVectorsRequest.add(indexOrAlias, "type", Integer.toString(i)); + multiTermVectorsRequest.add(indexOrAlias, Integer.toString(i)); indices.add(indexOrAlias); } internalCluster().coordOnlyNodeClient().multiTermVectors(multiTermVectorsRequest).actionGet(); diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTestCase.java b/server/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTestCase.java index 0393f5929ce38..f0e94cbd1694a 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTestCase.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/AbstractTermVectorsTestCase.java @@ -403,7 +403,7 @@ protected void validateResponse(TermVectorsResponse esResponse, Fields luceneFie } protected TermVectorsRequestBuilder getRequestForConfig(TestConfig config) { - return client().prepareTermVectors(randomBoolean() ? config.doc.index : config.doc.alias, config.doc.type, config.doc.id) + return client().prepareTermVectors(randomBoolean() ? config.doc.index : config.doc.alias, config.doc.id) .setPayloads(config.requestPayloads) .setOffsets(config.requestOffsets).setPositions(config.requestPositions).setFieldStatistics(true).setTermStatistics(true) .setSelectedFields(config.selectedFields).setRealtime(false); diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsIT.java b/server/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsIT.java index 442e27c0867b9..934f2563574d0 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsIT.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsIT.java @@ -81,7 +81,7 @@ public void testNoSuchDoc() throws Exception { client().prepareIndex("test", "type1", "666").setSource("field", "foo bar").execute().actionGet(); refresh(); for (int i = 0; i < 20; i++) { - ActionFuture termVector = client().termVectors(new TermVectorsRequest(indexOrAlias(), "type1", "" + i)); + ActionFuture termVector = client().termVectors(new TermVectorsRequest(indexOrAlias(), "" + i)); TermVectorsResponse actionGet = termVector.actionGet(); assertThat(actionGet, notNullValue()); assertThat(actionGet.getIndex(), equalTo("test")); @@ -105,7 +105,7 @@ public void testExistingFieldWithNoTermVectorsNoNPE() throws Exception { // when indexing a field that simply has a question mark, the term vectors will be null client().prepareIndex("test", "type1", "0").setSource("existingfield", "?").execute().actionGet(); refresh(); - ActionFuture termVector = client().termVectors(new TermVectorsRequest(indexOrAlias(), "type1", "0") + ActionFuture termVector = client().termVectors(new TermVectorsRequest(indexOrAlias(), "0") .selectedFields(new String[]{"existingfield"})); // lets see if the null term vectors are caught... @@ -130,7 +130,7 @@ public void testExistingFieldButNotInDocNPE() throws Exception { // when indexing a field that simply has a question mark, the term vectors will be null client().prepareIndex("test", "type1", "0").setSource("anotherexistingfield", 1).execute().actionGet(); refresh(); - ActionFuture termVectors = client().termVectors(new TermVectorsRequest(indexOrAlias(), "type1", "0") + ActionFuture termVectors = client().termVectors(new TermVectorsRequest(indexOrAlias(), "0") .selectedFields(randomBoolean() ? new String[]{"existingfield"} : null) .termStatistics(true) .fieldStatistics(true)); @@ -166,7 +166,7 @@ public void testNotIndexedField() throws Exception { indexRandom(true, indexBuilders); for (int i = 0; i < 4; i++) { - TermVectorsResponse resp = client().prepareTermVectors(indexOrAlias(), "type1", String.valueOf(i)) + TermVectorsResponse resp = client().prepareTermVectors(indexOrAlias(), String.valueOf(i)) .setSelectedFields("field" + i) .get(); assertThat(resp, notNullValue()); @@ -176,7 +176,7 @@ public void testNotIndexedField() throws Exception { } for (int i = 4; i < 6; i++) { - TermVectorsResponse resp = client().prepareTermVectors(indexOrAlias(), "type1", String.valueOf(i)) + TermVectorsResponse resp = client().prepareTermVectors(indexOrAlias(), String.valueOf(i)) .setSelectedFields("field" + i).get(); assertThat(resp.getIndex(), equalTo("test")); assertThat("field" + i + " :", resp.getFields().terms("field" + i), notNullValue()); @@ -208,7 +208,7 @@ public void testSimpleTermVectors() throws IOException { refresh(); } for (int i = 0; i < 10; i++) { - TermVectorsRequestBuilder resp = client().prepareTermVectors(indexOrAlias(), "type1", Integer.toString(i)).setPayloads(true) + TermVectorsRequestBuilder resp = client().prepareTermVectors(indexOrAlias(), Integer.toString(i)).setPayloads(true) .setOffsets(true).setPositions(true).setSelectedFields(); TermVectorsResponse response = resp.execute().actionGet(); assertThat(response.getIndex(), equalTo("test")); @@ -289,7 +289,7 @@ public void testRandomSingleTermVectors() throws IOException { boolean isPositionsRequested = randomBoolean(); String infoString = createInfoString(isPositionsRequested, isOffsetRequested, optionString); for (int i = 0; i < 10; i++) { - TermVectorsRequestBuilder resp = client().prepareTermVectors("test", "type1", Integer.toString(i)) + TermVectorsRequestBuilder resp = client().prepareTermVectors("test", Integer.toString(i)) .setOffsets(isOffsetRequested).setPositions(isPositionsRequested).setSelectedFields(); TermVectorsResponse response = resp.execute().actionGet(); assertThat(infoString + "doc id: " + i + " doesn't exists but should", response.isExists(), equalTo(true)); @@ -416,7 +416,7 @@ public void testSimpleTermVectorsWithGenerate() throws IOException { } for (int i = 0; i < 10; i++) { - TermVectorsResponse response = client().prepareTermVectors("test", "type1", Integer.toString(i)) + TermVectorsResponse response = client().prepareTermVectors("test", Integer.toString(i)) .setPayloads(true) .setOffsets(true) .setPositions(true) @@ -506,7 +506,7 @@ public void testDuelWithAndWithoutTermVectors() throws IOException, ExecutionExc for (int id = 0; id < content.length; id++) { Fields[] fields = new Fields[2]; for (int j = 0; j < indexNames.length; j++) { - TermVectorsResponse resp = client().prepareTermVectors(indexNames[j], "type1", String.valueOf(id)) + TermVectorsResponse resp = client().prepareTermVectors(indexNames[j], String.valueOf(id)) .setOffsets(true) .setPositions(true) .setSelectedFields("field1") @@ -580,7 +580,7 @@ public void testSimpleWildCards() throws IOException { client().prepareIndex("test", "type1", "0").setSource(source).get(); refresh(); - TermVectorsResponse response = client().prepareTermVectors(indexOrAlias(), "type1", "0").setSelectedFields("field*").get(); + TermVectorsResponse response = client().prepareTermVectors(indexOrAlias(), "0").setSelectedFields("field*").get(); assertThat("Doc doesn't exists but should", response.isExists(), equalTo(true)); assertThat(response.getIndex(), equalTo("test")); assertThat("All term vectors should have been generated", response.getFields().size(), equalTo(numFields)); @@ -615,7 +615,7 @@ public void testArtificialVsExisting() throws ExecutionException, InterruptedExc for (int i = 0; i < content.length; i++) { // request tvs from existing document - TermVectorsResponse respExisting = client().prepareTermVectors("test", "type1", String.valueOf(i)) + TermVectorsResponse respExisting = client().prepareTermVectors("test", String.valueOf(i)) .setOffsets(true) .setPositions(true) .setFieldStatistics(true) @@ -626,7 +626,6 @@ public void testArtificialVsExisting() throws ExecutionException, InterruptedExc // request tvs from artificial document TermVectorsResponse respArtificial = client().prepareTermVectors() .setIndex("test") - .setType("type1") .setRouting(String.valueOf(i)) // ensure we get the stats from the same shard as existing doc .setDoc(jsonBuilder() .startObject() @@ -658,7 +657,6 @@ public void testArtificialNoDoc() throws IOException { String text = "the quick brown fox jumps over the lazy dog"; TermVectorsResponse resp = client().prepareTermVectors() .setIndex("test") - .setType("type1") .setDoc(jsonBuilder() .startObject() .field("field1", text) @@ -736,7 +734,7 @@ public void testPerFieldAnalyzer() throws IOException { } // selected fields not specified - TermVectorsResponse response = client().prepareTermVectors(indexOrAlias(), "type1", "0") + TermVectorsResponse response = client().prepareTermVectors(indexOrAlias(), "0") .setPerFieldAnalyzer(perFieldAnalyzer) .get(); @@ -744,7 +742,7 @@ public void testPerFieldAnalyzer() throws IOException { checkAnalyzedFields(response.getFields(), withTermVectors, perFieldAnalyzer); // selected fields specified including some not in the mapping - response = client().prepareTermVectors(indexOrAlias(), "type1", "0") + response = client().prepareTermVectors(indexOrAlias(), "0") .setSelectedFields(selectedFields.toArray(Strings.EMPTY_ARRAY)) .setPerFieldAnalyzer(perFieldAnalyzer) .get(); @@ -784,7 +782,7 @@ public void testTermVectorsWithVersion() { .setSettings(Settings.builder().put("index.refresh_interval", -1))); ensureGreen(); - TermVectorsResponse response = client().prepareTermVectors("test", "type1", "1").get(); + TermVectorsResponse response = client().prepareTermVectors("test", "1").get(); assertThat(response.isExists(), equalTo(false)); logger.info("--> index doc 1"); @@ -793,12 +791,12 @@ public void testTermVectorsWithVersion() { // From translog: // version 0 means ignore version, which is the default - response = client().prepareTermVectors(indexOrAlias(), "type1", "1").setVersion(Versions.MATCH_ANY).get(); + response = client().prepareTermVectors(indexOrAlias(), "1").setVersion(Versions.MATCH_ANY).get(); assertThat(response.isExists(), equalTo(true)); assertThat(response.getId(), equalTo("1")); assertThat(response.getVersion(), equalTo(1L)); - response = client().prepareTermVectors(indexOrAlias(), "type1", "1").setVersion(1).get(); + response = client().prepareTermVectors(indexOrAlias(), "1").setVersion(1).get(); assertThat(response.isExists(), equalTo(true)); assertThat(response.getId(), equalTo("1")); assertThat(response.getVersion(), equalTo(1L)); @@ -814,13 +812,13 @@ public void testTermVectorsWithVersion() { refresh(); // version 0 means ignore version, which is the default - response = client().prepareTermVectors(indexOrAlias(), "type1", "1").setVersion(Versions.MATCH_ANY).setRealtime(false).get(); + response = client().prepareTermVectors(indexOrAlias(), "1").setVersion(Versions.MATCH_ANY).setRealtime(false).get(); assertThat(response.isExists(), equalTo(true)); assertThat(response.getId(), equalTo("1")); assertThat(response.getIndex(), equalTo("test")); assertThat(response.getVersion(), equalTo(1L)); - response = client().prepareTermVectors(indexOrAlias(), "type1", "1").setVersion(1).setRealtime(false).get(); + response = client().prepareTermVectors(indexOrAlias(), "1").setVersion(1).setRealtime(false).get(); assertThat(response.isExists(), equalTo(true)); assertThat(response.getId(), equalTo("1")); assertThat(response.getIndex(), equalTo("test")); @@ -839,7 +837,7 @@ public void testTermVectorsWithVersion() { // From translog: // version 0 means ignore version, which is the default - response = client().prepareTermVectors(indexOrAlias(), "type1", "1").setVersion(Versions.MATCH_ANY).get(); + response = client().prepareTermVectors(indexOrAlias(), "1").setVersion(Versions.MATCH_ANY).get(); assertThat(response.isExists(), equalTo(true)); assertThat(response.getId(), equalTo("1")); assertThat(response.getIndex(), equalTo("test")); @@ -852,7 +850,7 @@ public void testTermVectorsWithVersion() { //all good } - response = client().prepareTermVectors(indexOrAlias(), "type1", "1").setVersion(2).get(); + response = client().prepareTermVectors(indexOrAlias(), "1").setVersion(2).get(); assertThat(response.isExists(), equalTo(true)); assertThat(response.getId(), equalTo("1")); assertThat(response.getIndex(), equalTo("test")); @@ -862,7 +860,7 @@ public void testTermVectorsWithVersion() { refresh(); // version 0 means ignore version, which is the default - response = client().prepareTermVectors(indexOrAlias(), "type1", "1").setVersion(Versions.MATCH_ANY).setRealtime(false).get(); + response = client().prepareTermVectors(indexOrAlias(), "1").setVersion(Versions.MATCH_ANY).setRealtime(false).get(); assertThat(response.isExists(), equalTo(true)); assertThat(response.getId(), equalTo("1")); assertThat(response.getIndex(), equalTo("test")); @@ -875,7 +873,7 @@ public void testTermVectorsWithVersion() { //all good } - response = client().prepareTermVectors(indexOrAlias(), "type1", "1").setVersion(2).setRealtime(false).get(); + response = client().prepareTermVectors(indexOrAlias(), "1").setVersion(2).setRealtime(false).get(); assertThat(response.isExists(), equalTo(true)); assertThat(response.getId(), equalTo("1")); assertThat(response.getIndex(), equalTo("test")); @@ -909,7 +907,7 @@ public void testFilterLength() throws ExecutionException, InterruptedException, TermVectorsResponse response; for (int i = 0; i < numTerms; i++) { filterSettings.minWordLength = numTerms - i; - response = client().prepareTermVectors("test", "type1", "1") + response = client().prepareTermVectors("test", "1") .setSelectedFields("tags") .setFieldStatistics(true) .setTermStatistics(true) @@ -948,7 +946,7 @@ public void testFilterTermFreq() throws ExecutionException, InterruptedException TermVectorsResponse response; for (int i = 0; i < numTerms; i++) { filterSettings.maxNumTerms = i + 1; - response = client().prepareTermVectors("test", "type1", "1") + response = client().prepareTermVectors("test", "1") .setSelectedFields("tags") .setFieldStatistics(true) .setTermStatistics(true) @@ -983,7 +981,7 @@ public void testFilterDocFreq() throws ExecutionException, InterruptedException, TermVectorsResponse response; for (int i = 0; i < numDocs; i++) { filterSettings.maxNumTerms = i + 1; - response = client().prepareTermVectors("test", "type1", (numDocs - 1) + "") + response = client().prepareTermVectors("test", (numDocs - 1) + "") .setSelectedFields("tags") .setFieldStatistics(true) .setTermStatistics(true) @@ -1016,7 +1014,6 @@ public void testArtificialDocWithPreference() throws ExecutionException, Interru for (Integer shardId : shardIds) { TermVectorsResponse tvResponse = client().prepareTermVectors() .setIndex("test") - .setType("type1") .setPreference("_shards:" + shardId) .setDoc(jsonBuilder().startObject().field("field1", "random permutation").endObject()) .setFieldStatistics(true) @@ -1069,7 +1066,7 @@ public void testWithKeywordAndNormalizer() throws IOException, ExecutionExceptio for (int id = 0; id < content.length; id++) { Fields[] fields = new Fields[2]; for (int j = 0; j < indexNames.length; j++) { - TermVectorsResponse resp = client().prepareTermVectors(indexNames[j], "type1", String.valueOf(id)) + TermVectorsResponse resp = client().prepareTermVectors(indexNames[j], String.valueOf(id)) .setOffsets(true) .setPositions(true) .setSelectedFields("field1", "field2") diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java b/server/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java index 6379867d51604..6fa6540785ce3 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java @@ -169,7 +169,7 @@ public void testRandomPayloadWithDelimitedPayloadTokenFilter() throws IOExceptio client().prepareIndex("test", "type1", Integer.toString(1)) .setSource(jsonBuilder().startObject().field("field", queryString).endObject()).execute().actionGet(); client().admin().indices().prepareRefresh().get(); - TermVectorsRequestBuilder resp = client().prepareTermVectors("test", "type1", Integer.toString(1)) + TermVectorsRequestBuilder resp = client().prepareTermVectors("test", Integer.toString(1)) .setPayloads(true).setOffsets(true).setPositions(true).setSelectedFields(); TermVectorsResponse response = resp.execute().actionGet(); assertThat("doc id 1 doesn't exists but should", response.isExists(), equalTo(true)); diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java b/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java index 08751ffe058ec..9521c882929c9 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java @@ -70,7 +70,7 @@ public void testDuelESLucene() throws Exception { } public void testMissingIndexThrowsMissingIndex() throws Exception { - TermVectorsRequestBuilder requestBuilder = client().prepareTermVectors("testX", "typeX", Integer.toString(1)); + TermVectorsRequestBuilder requestBuilder = client().prepareTermVectors("testX", Integer.toString(1)); MultiTermVectorsRequestBuilder mtvBuilder = client().prepareMultiTermVectors(); mtvBuilder.add(requestBuilder.request()); MultiTermVectorsResponse response = mtvBuilder.execute().actionGet(); @@ -94,9 +94,9 @@ public void testMultiTermVectorsWithVersion() throws Exception { // Version from translog response = client().prepareMultiTermVectors() - .add(new TermVectorsRequest(indexOrAlias(), "type1", "1").selectedFields("field").version(Versions.MATCH_ANY)) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "1").selectedFields("field").version(1)) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "1").selectedFields("field").version(2)) + .add(new TermVectorsRequest(indexOrAlias(), "1").selectedFields("field").version(Versions.MATCH_ANY)) + .add(new TermVectorsRequest(indexOrAlias(), "1").selectedFields("field").version(1)) + .add(new TermVectorsRequest(indexOrAlias(), "1").selectedFields("field").version(2)) .get(); assertThat(response.getResponses().length, equalTo(3)); // [0] version doesn't matter, which is the default @@ -118,10 +118,10 @@ public void testMultiTermVectorsWithVersion() throws Exception { //Version from Lucene index refresh(); response = client().prepareMultiTermVectors() - .add(new TermVectorsRequest(indexOrAlias(), "type1", "1").selectedFields("field") + .add(new TermVectorsRequest(indexOrAlias(), "1").selectedFields("field") .version(Versions.MATCH_ANY).realtime(false)) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "1").selectedFields("field").version(1).realtime(false)) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "1").selectedFields("field").version(2).realtime(false)) + .add(new TermVectorsRequest(indexOrAlias(), "1").selectedFields("field").version(1).realtime(false)) + .add(new TermVectorsRequest(indexOrAlias(), "1").selectedFields("field").version(2).realtime(false)) .get(); assertThat(response.getResponses().length, equalTo(3)); // [0] version doesn't matter, which is the default @@ -145,9 +145,9 @@ public void testMultiTermVectorsWithVersion() throws Exception { // Version from translog response = client().prepareMultiTermVectors() - .add(new TermVectorsRequest(indexOrAlias(), "type1", "2").selectedFields("field").version(Versions.MATCH_ANY)) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "2").selectedFields("field").version(1)) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "2").selectedFields("field").version(2)) + .add(new TermVectorsRequest(indexOrAlias(), "2").selectedFields("field").version(Versions.MATCH_ANY)) + .add(new TermVectorsRequest(indexOrAlias(), "2").selectedFields("field").version(1)) + .add(new TermVectorsRequest(indexOrAlias(), "2").selectedFields("field").version(2)) .get(); assertThat(response.getResponses().length, equalTo(3)); // [0] version doesn't matter, which is the default @@ -171,9 +171,9 @@ public void testMultiTermVectorsWithVersion() throws Exception { //Version from Lucene index refresh(); response = client().prepareMultiTermVectors() - .add(new TermVectorsRequest(indexOrAlias(), "type1", "2").selectedFields("field").version(Versions.MATCH_ANY)) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "2").selectedFields("field").version(1)) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "2").selectedFields("field").version(2)) + .add(new TermVectorsRequest(indexOrAlias(), "2").selectedFields("field").version(Versions.MATCH_ANY)) + .add(new TermVectorsRequest(indexOrAlias(), "2").selectedFields("field").version(1)) + .add(new TermVectorsRequest(indexOrAlias(), "2").selectedFields("field").version(2)) .get(); assertThat(response.getResponses().length, equalTo(3)); // [0] version doesn't matter, which is the default diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java b/server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java index 8ab452950a87a..ec5a5a8e40999 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java @@ -65,7 +65,7 @@ public class TermVectorsUnitTests extends ESTestCase { public void testStreamResponse() throws Exception { - TermVectorsResponse outResponse = new TermVectorsResponse("a", "b", "c"); + TermVectorsResponse outResponse = new TermVectorsResponse("a", "c"); outResponse.setExists(true); writeStandardTermVector(outResponse); @@ -82,7 +82,7 @@ public void testStreamResponse() throws Exception { // see if correct checkIfStandardTermVector(inResponse); - outResponse = new TermVectorsResponse("a", "b", "c"); + outResponse = new TermVectorsResponse("a", "c"); writeEmptyTermVector(outResponse); // write outBuffer = new ByteArrayOutputStream(); @@ -175,7 +175,7 @@ public void testRestRequestParsing() throws Exception { BytesReference inputBytes = new BytesArray( " {\"fields\" : [\"a\", \"b\",\"c\"], \"offsets\":false, \"positions\":false, \"payloads\":true}"); - TermVectorsRequest tvr = new TermVectorsRequest(null, null, null); + TermVectorsRequest tvr = new TermVectorsRequest(null, null); XContentParser parser = createParser(JsonXContent.jsonXContent, inputBytes); TermVectorsRequest.parseRequest(tvr, parser); @@ -196,7 +196,7 @@ public void testRestRequestParsing() throws Exception { RestTermVectorsAction.addFieldStringsFromParameter(tvr, additionalFields); inputBytes = new BytesArray(" {\"offsets\":false, \"positions\":false, \"payloads\":true}"); - tvr = new TermVectorsRequest(null, null, null); + tvr = new TermVectorsRequest(null, null); parser = createParser(JsonXContent.jsonXContent, inputBytes); TermVectorsRequest.parseRequest(tvr, parser); additionalFields = ""; @@ -211,7 +211,7 @@ public void testRestRequestParsing() throws Exception { public void testRequestParsingThrowsException() throws Exception { BytesReference inputBytes = new BytesArray( " {\"fields\" : \"a, b,c \", \"offsets\":false, \"positions\":false, \"payloads\":true, \"meaningless_term\":2}"); - TermVectorsRequest tvr = new TermVectorsRequest(null, null, null); + TermVectorsRequest tvr = new TermVectorsRequest(null, null); boolean threwException = false; try { XContentParser parser = createParser(JsonXContent.jsonXContent, inputBytes); @@ -225,7 +225,7 @@ public void testRequestParsingThrowsException() throws Exception { public void testStreamRequest() throws IOException { for (int i = 0; i < 10; i++) { - TermVectorsRequest request = new TermVectorsRequest("index", "type", "id"); + TermVectorsRequest request = new TermVectorsRequest("index", "id"); request.offsets(random().nextBoolean()); request.fieldStatistics(random().nextBoolean()); request.payloads(random().nextBoolean()); @@ -243,7 +243,7 @@ public void testStreamRequest() throws IOException { // read ByteArrayInputStream esInBuffer = new ByteArrayInputStream(outBuffer.toByteArray()); InputStreamStreamInput esBuffer = new InputStreamStreamInput(esInBuffer); - TermVectorsRequest req2 = new TermVectorsRequest(null, null, null); + TermVectorsRequest req2 = new TermVectorsRequest(null, null); req2.readFrom(esBuffer); assertThat(request.offsets(), equalTo(req2.offsets())); @@ -300,7 +300,6 @@ public void testMultiParser() throws Exception { request.add(new TermVectorsRequest(), data); checkParsedParameters(request); - assertWarnings(RestTermVectorsAction.TYPES_DEPRECATION_MESSAGE); } void checkParsedParameters(MultiTermVectorsRequest request) { @@ -313,7 +312,6 @@ void checkParsedParameters(MultiTermVectorsRequest request) { fields.add("c"); for (TermVectorsRequest singleRequest : request.requests) { assertThat(singleRequest.index(), equalTo("testidx")); - assertThat(singleRequest.type(), equalTo("test")); assertThat(singleRequest.payloads(), equalTo(false)); assertThat(singleRequest.positions(), equalTo(false)); assertThat(singleRequest.offsets(), equalTo(false)); @@ -332,14 +330,12 @@ public void testMultiParserFilter() throws Exception { request.add(new TermVectorsRequest(), data); checkParsedFilterParameters(request); - assertWarnings(RestTermVectorsAction.TYPES_DEPRECATION_MESSAGE); } void checkParsedFilterParameters(MultiTermVectorsRequest multiRequest) { Set ids = new HashSet<>(Arrays.asList("1", "2")); for (TermVectorsRequest request : multiRequest.requests) { assertThat(request.index(), equalTo("testidx")); - assertThat(request.type(), equalTo("test")); assertTrue(ids.remove(request.id())); assertNotNull(request.filterSettings()); assertThat(request.filterSettings().maxNumTerms, equalTo(20)); diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsActionTests.java b/server/src/test/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsActionTests.java index db50f75272820..35e0de175b2fa 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsActionTests.java @@ -168,8 +168,8 @@ public void testTransportMultiGetAction() { final Task task = createTask(); final NodeClient client = new NodeClient(Settings.EMPTY, threadPool); final MultiTermVectorsRequestBuilder request = new MultiTermVectorsRequestBuilder(client, MultiTermVectorsAction.INSTANCE); - request.add(new TermVectorsRequest("index1", "_doc", "1")); - request.add(new TermVectorsRequest("index2", "_doc", "2")); + request.add(new TermVectorsRequest("index1", "1")); + request.add(new TermVectorsRequest("index2", "2")); final AtomicBoolean shardActionInvoked = new AtomicBoolean(false); transportAction = new TransportMultiTermVectorsAction(transportService, clusterService, shardAction, @@ -193,8 +193,8 @@ public void testTransportMultiGetAction_withMissingRouting() { final Task task = createTask(); final NodeClient client = new NodeClient(Settings.EMPTY, threadPool); final MultiTermVectorsRequestBuilder request = new MultiTermVectorsRequestBuilder(client, MultiTermVectorsAction.INSTANCE); - request.add(new TermVectorsRequest("index2", "_doc", "1").routing("1")); - request.add(new TermVectorsRequest("index2", "_doc", "2")); + request.add(new TermVectorsRequest("index2", "1").routing("1")); + request.add(new TermVectorsRequest("index2", "2")); final AtomicBoolean shardActionInvoked = new AtomicBoolean(false); transportAction = new TransportMultiTermVectorsAction(transportService, clusterService, shardAction, diff --git a/server/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java index 56e7a32347265..9f82ea8a690e2 100644 --- a/server/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java @@ -96,18 +96,7 @@ private static String[] randomStringFields() { private Item generateRandomItem() { String index = randomBoolean() ? getIndex().getName() : null; // indexed item or artificial document - Item item; - - if (randomBoolean()) { - item = randomBoolean() - ? new Item(index, randomAlphaOfLength(10)) - : new Item(index, randomArtificialDoc()); - } else { - String type = "doc"; - item = randomBoolean() - ? new Item(index, type, randomAlphaOfLength(10)) - : new Item(index, type, randomArtificialDoc()); - } + Item item = randomBoolean() ? new Item(index, randomAlphaOfLength(10)) : new Item(index, randomArtificialDoc()); // if no field is specified MLT uses all mapped fields for this item if (randomBoolean()) { @@ -235,7 +224,7 @@ protected MultiTermVectorsResponse executeMultiTermVectors(MultiTermVectorsReque MultiTermVectorsItemResponse[] responses = new MultiTermVectorsItemResponse[mtvRequest.size()]; int i = 0; for (TermVectorsRequest request : mtvRequest) { - TermVectorsResponse response = new TermVectorsResponse(request.index(), request.type(), request.id()); + TermVectorsResponse response = new TermVectorsResponse(request.index(), request.id()); response.setExists(true); Fields generatedFields; if (request.doc() != null) { @@ -386,11 +375,9 @@ public void testFromJson() throws IOException { " \"fields\" : [ \"title\", \"description\" ],\n" + " \"like\" : [ \"and potentially some more text here as well\", {\n" + " \"_index\" : \"imdb\",\n" + - " \"_type\" : \"movies\",\n" + " \"_id\" : \"1\"\n" + " }, {\n" + " \"_index\" : \"imdb\",\n" + - " \"_type\" : \"movies\",\n" + " \"_id\" : \"2\"\n" + " } ],\n" + " \"max_query_terms\" : 12,\n" + @@ -420,9 +407,6 @@ protected QueryBuilder parseQuery(XContentParser parser) throws IOException { assertThat(query, instanceOf(MoreLikeThisQueryBuilder.class)); MoreLikeThisQueryBuilder mltQuery = (MoreLikeThisQueryBuilder) query; - if (mltQuery.isTypeless() == false) { - assertWarnings(MoreLikeThisQueryBuilder.TYPES_DEPRECATION_MESSAGE); - } return query; } diff --git a/server/src/test/java/org/elasticsearch/index/termvectors/TermVectorsServiceTests.java b/server/src/test/java/org/elasticsearch/index/termvectors/TermVectorsServiceTests.java index 034e7daaf7f99..6d192f584f0de 100644 --- a/server/src/test/java/org/elasticsearch/index/termvectors/TermVectorsServiceTests.java +++ b/server/src/test/java/org/elasticsearch/index/termvectors/TermVectorsServiceTests.java @@ -69,7 +69,7 @@ public void testTook() throws Exception { List longs = Stream.of(abs(randomLong()), abs(randomLong())).sorted().collect(toList()); - TermVectorsRequest request = new TermVectorsRequest("test", "type1", "0"); + TermVectorsRequest request = new TermVectorsRequest("test", "0"); TermVectorsResponse response = TermVectorsService.getTermVectors(shard, request, longs.iterator()::next); assertThat(response, notNullValue()); @@ -103,22 +103,22 @@ public void testDocFreqs() throws IOException { } bulk.get(); - TermVectorsRequest request = new TermVectorsRequest("test", "_doc", "0").termStatistics(true); + TermVectorsRequest request = new TermVectorsRequest("test", "0").termStatistics(true); IndicesService indicesService = getInstanceFromNode(IndicesService.class); IndexService test = indicesService.indexService(resolveIndex("test")); IndexShard shard = test.getShardOrNull(0); assertThat(shard, notNullValue()); - TermVectorsResponse response = TermVectorsService.getTermVectors(shard, request); - assertEquals(1, response.getFields().size()); + TermVectorsResponse response = TermVectorsService.getTermVectors(shard, request); + assertEquals(1, response.getFields().size()); Terms terms = response.getFields().terms("text"); TermsEnum iterator = terms.iterator(); while (iterator.next() != null) { assertEquals(max, iterator.docFreq()); } - } - + } + public void testWithIndexedPhrases() throws IOException { XContentBuilder mapping = jsonBuilder() .startObject() @@ -126,7 +126,7 @@ public void testWithIndexedPhrases() throws IOException { .startObject("properties") .startObject("text") .field("type", "text") - .field("index_phrases", true) + .field("index_phrases", true) .field("term_vector", "with_positions_offsets_payloads") .endObject() .endObject() @@ -146,13 +146,13 @@ public void testWithIndexedPhrases() throws IOException { } bulk.get(); - TermVectorsRequest request = new TermVectorsRequest("test", "_doc", "0").termStatistics(true); + TermVectorsRequest request = new TermVectorsRequest("test", "0").termStatistics(true); IndicesService indicesService = getInstanceFromNode(IndicesService.class); IndexService test = indicesService.indexService(resolveIndex("test")); IndexShard shard = test.getShardOrNull(0); assertThat(shard, notNullValue()); - TermVectorsResponse response = TermVectorsService.getTermVectors(shard, request); + TermVectorsResponse response = TermVectorsService.getTermVectors(shard, request); assertEquals(2, response.getFields().size()); Terms terms = response.getFields().terms("text"); @@ -160,11 +160,11 @@ public void testWithIndexedPhrases() throws IOException { while (iterator.next() != null) { assertEquals(max, iterator.docFreq()); } - + Terms phrases = response.getFields().terms("text._index_phrase"); TermsEnum phraseIterator = phrases.iterator(); while (phraseIterator.next() != null) { assertEquals(max, phraseIterator.docFreq()); } - } + } } diff --git a/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java b/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java index b383a80296247..34e754f915bfa 100644 --- a/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java +++ b/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java @@ -584,17 +584,17 @@ public void testRequiredRoutingMappingVariousAPIs() throws Exception { } logger.info("--> verifying term vector with id [1], with routing [0], should succeed"); - TermVectorsResponse termVectorsResponse = client().prepareTermVectors(indexOrAlias(), "type1", "1") + TermVectorsResponse termVectorsResponse = client().prepareTermVectors(indexOrAlias(), "1") .setRouting(routingValue) .get(); assertThat(termVectorsResponse.isExists(), equalTo(true)); assertThat(termVectorsResponse.getId(), equalTo("1")); try { - client().prepareTermVectors(indexOrAlias(), "type1", "1").get(); + client().prepareTermVectors(indexOrAlias(), "1").get(); fail(); } catch (RoutingMissingException e) { - assertThat(e.getMessage(), equalTo("routing is required for [test]/[type1]/[1]")); + assertThat(e.getMessage(), equalTo("routing is required for [test]/[1]")); } UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1").setRouting(routingValue) @@ -632,9 +632,9 @@ public void testRequiredRoutingMappingVariousAPIs() throws Exception { assertThat(multiGetResponse.getResponses()[1].getFailure().getMessage(), equalTo("routing is required for [test]/[type1]/[2]")); MultiTermVectorsResponse multiTermVectorsResponse = client().prepareMultiTermVectors() - .add(new TermVectorsRequest(indexOrAlias(), "type1", "1") + .add(new TermVectorsRequest(indexOrAlias(), "1") .routing(routingValue)) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "2") + .add(new TermVectorsRequest(indexOrAlias(), "2") .routing(routingValue)) .get(); assertThat(multiTermVectorsResponse.getResponses().length, equalTo(2)); @@ -648,8 +648,7 @@ public void testRequiredRoutingMappingVariousAPIs() throws Exception { assertThat(multiTermVectorsResponse.getResponses()[1].getResponse().isExists(), equalTo(true)); multiTermVectorsResponse = client().prepareMultiTermVectors() - .add(new TermVectorsRequest(indexOrAlias(), "type1", "1")) - .add(new TermVectorsRequest(indexOrAlias(), "type1", "2")).get(); + .add(new TermVectorsRequest(indexOrAlias(), "1")).add(new TermVectorsRequest(indexOrAlias(), "2")).get(); assertThat(multiTermVectorsResponse.getResponses().length, equalTo(2)); assertThat(multiTermVectorsResponse.getResponses()[0].getId(), equalTo("1")); assertThat(multiTermVectorsResponse.getResponses()[0].isFailed(), equalTo(true)); diff --git a/server/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java b/server/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java index f2239d80d7f62..da16eeb039c8a 100644 --- a/server/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java +++ b/server/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java @@ -129,7 +129,7 @@ public void hitExecute(SearchContext context, HitContext hitContext) { hitContext.hit().getFields().put(NAME, hitField); } TermVectorsRequest termVectorsRequest = new TermVectorsRequest(context.indexShard().shardId().getIndex().getName(), - hitContext.hit().getType(), hitContext.hit().getId()); + hitContext.hit().getId()); TermVectorsResponse termVector = TermVectorsService.getTermVectors(context.indexShard(), termVectorsRequest); try { Map tv = new HashMap<>(); diff --git a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java index dabbecf481bfb..02d31f6ba26ab 100644 --- a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java +++ b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java @@ -112,7 +112,7 @@ public void testSimpleMoreLikeThisWithTypes() throws Exception { logger.info("Running moreLikeThis"); SearchResponse response = client().prepareSearch().setQuery( - new MoreLikeThisQueryBuilder(null, new Item[] {new Item("test", "type1", "1")}).minTermFreq(1).minDocFreq(1)).get(); + new MoreLikeThisQueryBuilder(null, new Item[] {new Item("test", "1")}).minTermFreq(1).minDocFreq(1)).get(); assertHitCount(response, 1L); } @@ -243,7 +243,7 @@ public void testMoreLikeThisWithAliasesInLikeDocuments() throws Exception { refresh(indexName); SearchResponse response = client().prepareSearch().setQuery( - new MoreLikeThisQueryBuilder(null, new Item[] {new Item(aliasName, typeName, "1")}).minTermFreq(1).minDocFreq(1)).get(); + new MoreLikeThisQueryBuilder(null, new Item[] {new Item(aliasName, "1")}).minTermFreq(1).minDocFreq(1)).get(); assertHitCount(response, 2L); assertThat(response.getHits().getAt(0).getId(), equalTo("3")); } @@ -261,11 +261,11 @@ public void testMoreLikeThisIssue2197() throws Exception { assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN)); SearchResponse response = client().prepareSearch().setQuery( - new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "bar", "1")})).get(); + new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "1")})).get(); assertNoFailures(response); assertThat(response, notNullValue()); response = client().prepareSearch().setQuery( - new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "bar", "1")})).get(); + new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "1")})).get(); assertNoFailures(response); assertThat(response, notNullValue()); } @@ -286,7 +286,7 @@ public void testMoreLikeWithCustomRouting() throws Exception { client().admin().indices().prepareRefresh("foo").get(); SearchResponse response = client().prepareSearch().setQuery( - new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "bar", "1").routing("2")})).get(); + new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "1").routing("2")})).get(); assertNoFailures(response); assertThat(response, notNullValue()); } @@ -308,7 +308,7 @@ public void testMoreLikeThisIssueRoutingNotSerialized() throws Exception { .get(); client().admin().indices().prepareRefresh("foo").get(); SearchResponse response = client().prepareSearch().setQuery( - new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "bar", "1").routing("4000")})).get(); + new MoreLikeThisQueryBuilder(null, new Item[] {new Item("foo", "1").routing("4000")})).get(); assertNoFailures(response); assertThat(response, notNullValue()); } @@ -410,7 +410,7 @@ public void testMoreLikeThisWithFieldAlias() throws Exception { index("test", "_doc", "2", "text", "lucene release"); refresh(); - Item item = new Item("test", "_doc", "1"); + Item item = new Item("test", "1"); QueryBuilder query = QueryBuilders.moreLikeThisQuery(new String[] {"alias"}, null, new Item[] {item}) .minTermFreq(1) .minDocFreq(1); @@ -446,7 +446,7 @@ public void testSimpleMoreLikeInclude() throws Exception { assertOrderedSearchHits(response, "1", "2"); response = client().prepareSearch().setQuery( - new MoreLikeThisQueryBuilder(null, new Item[] {new Item("test", "type1", "2")}).minTermFreq(1).minDocFreq(1).include(true) + new MoreLikeThisQueryBuilder(null, new Item[] {new Item("test", "2")}).minTermFreq(1).minDocFreq(1).include(true) .minimumShouldMatch("0%")).get(); assertOrderedSearchHits(response, "2", "1"); @@ -475,7 +475,7 @@ public void testSimpleMoreLikeThisIds() throws Exception { indexRandom(true, builders); logger.info("Running MoreLikeThis"); - Item[] items = new Item[] { new Item(null, null, "1")}; + Item[] items = new Item[] { new Item(null, "1")}; MoreLikeThisQueryBuilder queryBuilder = QueryBuilders.moreLikeThisQuery(new String[] {"text"}, null, items).include(true) .minTermFreq(1).minDocFreq(1); SearchResponse mltResponse = client().prepareSearch().setQuery(queryBuilder).get(); @@ -504,7 +504,7 @@ public void testMoreLikeThisMultiValueFields() throws Exception { for (int i = 0; i < maxIters; i++) { int max_query_terms = randomIntBetween(1, values.length); logger.info("Running More Like This with max_query_terms = {}", max_query_terms); - MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery(new String[] {"text"}, null, new Item[] {new Item(null, null, "0")}) + MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery(new String[] {"text"}, null, new Item[] {new Item(null, "0")}) .minTermFreq(1).minDocFreq(1) .maxQueryTerms(max_query_terms).minimumShouldMatch("0%"); SearchResponse response = client().prepareSearch("test") @@ -567,7 +567,7 @@ public void testMoreLikeThisArtificialDocs() throws Exception { logger.info("Checking the document matches ..."); // routing to ensure we hit the shard with the doc - MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery(new Item[] {new Item("test", "type1", doc).routing("0")}) + MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery(new Item[] {new Item("test", doc).routing("0")}) .minTermFreq(0) .minDocFreq(0) .maxQueryTerms(100) @@ -597,7 +597,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception { .field("text", "Hello World!") .field("date", "this is not a date!") .endObject(); - MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery(new Item[] {new Item("test", "type1", malformedFieldDoc)}) + MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery(new Item[] {new Item("test", malformedFieldDoc)}) .minTermFreq(0) .minDocFreq(0) .minimumShouldMatch("0%"); @@ -608,7 +608,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception { logger.info("Checking with an empty document ..."); XContentBuilder emptyDoc = jsonBuilder().startObject().endObject(); - mltQuery = moreLikeThisQuery(null, new Item[] {new Item("test", "type1", emptyDoc)}) + mltQuery = moreLikeThisQuery(null, new Item[] {new Item("test", emptyDoc)}) .minTermFreq(0) .minDocFreq(0) .minimumShouldMatch("0%"); @@ -623,7 +623,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception { .field("text", "Hello World!") .field("date", "1000-01-01") // should be properly parsed but ignored ... .endObject(); - mltQuery = moreLikeThisQuery(null, new Item[] {new Item("test", "type1", normalDoc)}) + mltQuery = moreLikeThisQuery(null, new Item[] {new Item("test", normalDoc)}) .minTermFreq(0) .minDocFreq(0) .minimumShouldMatch("100%"); // strict all terms must match but date is ignored @@ -653,7 +653,7 @@ public void testMoreLikeThisUnlike() throws ExecutionException, InterruptedExcep indexRandom(true, builders); logger.info("First check the document matches all indexed docs."); - MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery(new Item[] {new Item("test", "type1", doc)}) + MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery(new Item[] {new Item("test", doc)}) .minTermFreq(0) .minDocFreq(0) .maxQueryTerms(100) @@ -666,8 +666,8 @@ public void testMoreLikeThisUnlike() throws ExecutionException, InterruptedExcep logger.info("Now check like this doc, but ignore one doc in the index, then two and so on..."); List docs = new ArrayList<>(numFields); for (int i = 0; i < numFields; i++) { - docs.add(new Item("test", "type1", i+"")); - mltQuery = moreLikeThisQuery(null, new Item[] {new Item("test", "type1", doc)}) + docs.add(new Item("test", i+"")); + mltQuery = moreLikeThisQuery(null, new Item[] {new Item("test", doc)}) .unlike(docs.toArray(new Item[docs.size()])) .minTermFreq(0) .minDocFreq(0) @@ -724,7 +724,7 @@ public void testWithRouting() throws IOException { client().prepareIndex("index", "type", "3").setRouting("4").setSource("text", "this is yet another document").get(); refresh("index"); - Item item = new Item("index", "type", "2").routing("1"); + Item item = new Item("index", "2").routing("1"); MoreLikeThisQueryBuilder moreLikeThisQueryBuilder = new MoreLikeThisQueryBuilder(new String[]{"text"}, null, new Item[]{item}); moreLikeThisQueryBuilder.minTermFreq(1); moreLikeThisQueryBuilder.minDocFreq(1); @@ -753,7 +753,7 @@ public void testWithMissingRouting() throws IOException { Throwable cause = exception.getCause(); assertThat(cause, instanceOf(RoutingMissingException.class)); - assertThat(cause.getMessage(), equalTo("routing is required for [test]/[_doc]/[1]")); + assertThat(cause.getMessage(), equalTo("routing is required for [test]/[1]")); } { @@ -761,8 +761,8 @@ public void testWithMissingRouting() throws IOException { SearchPhaseExecutionException exception = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch().setQuery(new MoreLikeThisQueryBuilder(null, new Item[]{ new Item("test", "1").routing("1"), - new Item("test", "type1", "2"), - new Item("test", "type1", "3") + new Item("test", "2"), + new Item("test", "3") }).minTermFreq(1).minDocFreq(1)).get()); Throwable cause = exception.getCause(); diff --git a/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java b/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java index 7691b3346d72f..c170ca76c49da 100644 --- a/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java +++ b/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java @@ -212,7 +212,7 @@ public void testExplainWithRewriteValidateQuery() { containsString("(field:jumps)^0.75"), true); // more like this queries - Item[] items = new Item[] { new Item(null, null, "1")}; + Item[] items = new Item[] { new Item(null, "1") }; assertExplanation(QueryBuilders.moreLikeThisQuery(new String[] { "field" }, null, items) .include(true).minTermFreq(1).minDocFreq(1).maxQueryTerms(2), containsString("field:huge field:pidgin"), true); diff --git a/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest1.json b/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest1.json index fcb5e3a927ad9..aecbcdc9d69bb 100644 --- a/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest1.json +++ b/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest1.json @@ -7,7 +7,6 @@ "offsets":false, "positions":false, "fields":["a","b","c"], - "_index": "testidx", - "_type":"test" + "_index": "testidx" } } \ No newline at end of file diff --git a/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest2.json b/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest2.json index a0709effe709b..793bdda2a33b6 100644 --- a/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest2.json +++ b/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest2.json @@ -8,8 +8,7 @@ "offsets": false, "positions": false, "fields":["a","b","c"], - "_index": "testidx", - "_type": "test" + "_index": "testidx" }, { "_id": "2", @@ -19,8 +18,7 @@ "offsets": false, "positions": false, "fields":["a","b","c"], - "_index": "testidx", - "_type": "test" + "_index": "testidx" } ] } \ No newline at end of file diff --git a/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest3.json b/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest3.json index 457f43cdc9aca..2c405919111aa 100644 --- a/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest3.json +++ b/server/src/test/resources/org/elasticsearch/action/termvectors/multiRequest3.json @@ -2,7 +2,6 @@ "ids": ["1","2"], "parameters": { "_index": "testidx", - "_type": "test", "filter": { "max_num_terms": 20, "min_term_freq": 1, diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java index 39407ef735974..98f67d6718be4 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java @@ -135,7 +135,7 @@ public void testSearchAndGetAPIsAreThrottled() throws InterruptedException, IOEx numRefreshes += 3; break; case 2: - client().prepareTermVectors("index", "_doc", "" + randomIntBetween(0, 9)).execute(listener); + client().prepareTermVectors("index", "" + randomIntBetween(0, 9)).execute(listener); break; case 3: client().prepareExplain("index", "_doc", "" + randomIntBetween(0, 9)).setQuery(new MatchAllQueryBuilder()) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java index d23ca8e11428e..59a6c4b31fe15 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java @@ -424,47 +424,47 @@ public void testTVApi() throws Exception { boolean realtime = randomBoolean(); TermVectorsResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); assertThat(response.getId(), is("1")); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "2") + .prepareTermVectors("test", "2") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); assertThat(response.getId(), is("2")); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); assertThat(response.getId(), is("1")); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "2") + .prepareTermVectors("test", "2") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); assertThat(response.getId(), is("2")); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(false)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "2") + .prepareTermVectors("test", "2") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(false)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "3") + .prepareTermVectors("test", "3") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(false)); @@ -490,7 +490,7 @@ public void testMTVApi() throws Exception { MultiTermVectorsResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -498,7 +498,7 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "2").realtime(realtime)) + .add(new TermVectorsRequest("test", "2").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -506,8 +506,7 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) - .add(new TermVectorsRequest("test", "type1", "2").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)).add(new TermVectorsRequest("test", "2").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(2)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -517,21 +516,21 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(false)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "2").realtime(realtime)) + .add(new TermVectorsRequest("test", "2").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(false)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "3").realtime(realtime)) + .add(new TermVectorsRequest("test", "3").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(false)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java index c10dc51226ec2..6b87b5d41faf2 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java @@ -1164,7 +1164,7 @@ public void testTVApi() throws Exception { boolean realtime = randomBoolean(); TermVectorsResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); @@ -1172,7 +1172,7 @@ public void testTVApi() throws Exception { assertThat(response.getFields().terms("field1").size(), equalTo(1L)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); @@ -1180,7 +1180,7 @@ public void testTVApi() throws Exception { assertThat(response.getFields().terms("field2").size(), equalTo(1L)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); @@ -1189,14 +1189,14 @@ public void testTVApi() throws Exception { assertThat(response.getFields().terms("field2").size(), equalTo(1L)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); assertThat(response.getFields().size(), equalTo(0)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user5", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); @@ -1206,7 +1206,7 @@ public void testTVApi() throws Exception { assertThat(response.getFields().terms("field3").size(), equalTo(1L)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user6", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); @@ -1216,7 +1216,7 @@ public void testTVApi() throws Exception { assertThat(response.getFields().terms("field3").size(), equalTo(1L)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user7", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); @@ -1226,7 +1226,7 @@ public void testTVApi() throws Exception { assertThat(response.getFields().terms("field3").size(), equalTo(1L)); response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user8", USERS_PASSWD))) - .prepareTermVectors("test", "type1", "1") + .prepareTermVectors("test", "1") .setRealtime(realtime) .get(); assertThat(response.isExists(), is(true)); @@ -1249,7 +1249,7 @@ public void testMTVApi() throws Exception { MultiTermVectorsResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -1258,7 +1258,7 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user2", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -1267,7 +1267,7 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user3", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -1277,7 +1277,7 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user4", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -1285,7 +1285,7 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user5", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -1296,7 +1296,7 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user6", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -1307,7 +1307,7 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user7", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); @@ -1318,7 +1318,7 @@ public void testMTVApi() throws Exception { response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user8", USERS_PASSWD))) .prepareMultiTermVectors() - .add(new TermVectorsRequest("test", "type1", "1").realtime(realtime)) + .add(new TermVectorsRequest("test", "1").realtime(realtime)) .get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), is(true)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java index b370c8e2b6b0f..2b085c6834581 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java @@ -155,9 +155,9 @@ import static org.elasticsearch.test.SecurityTestsUtils.assertAuthenticationException; import static org.elasticsearch.test.SecurityTestsUtils.assertThrowsAuthorizationException; import static org.elasticsearch.test.SecurityTestsUtils.assertThrowsAuthorizationExceptionRunAs; -import static org.elasticsearch.xpack.security.audit.logfile.LoggingAuditTrail.PRINCIPAL_ROLES_FIELD_NAME; import static org.elasticsearch.xpack.core.security.index.RestrictedIndicesNames.INTERNAL_SECURITY_MAIN_INDEX_7; import static org.elasticsearch.xpack.core.security.index.RestrictedIndicesNames.SECURITY_MAIN_ALIAS; +import static org.elasticsearch.xpack.security.audit.logfile.LoggingAuditTrail.PRINCIPAL_ROLES_FIELD_NAME; import static org.hamcrest.Matchers.arrayContainingInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.endsWith; @@ -882,7 +882,7 @@ public void testGrantAllRestrictedUserCannotExecuteOperationAgainstSecurityIndic new Tuple<>(BulkAction.NAME + "[s]", new IndexRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7)))); requests.add(new Tuple<>(SearchAction.NAME, new SearchRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7)))); requests.add(new Tuple<>(TermVectorsAction.NAME, - new TermVectorsRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7), "type", "id"))); + new TermVectorsRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7), "id"))); requests.add(new Tuple<>(GetAction.NAME, new GetRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7), "id"))); requests.add(new Tuple<>(IndicesAliasesAction.NAME, new IndicesAliasesRequest() .addAliasAction(AliasActions.add().alias("security_alias").index(INTERNAL_SECURITY_MAIN_INDEX_7)))); @@ -1007,11 +1007,11 @@ public void testSuperusersCanExecuteOperationAgainstSecurityIndex() throws IOExc createBulkShardRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7), IndexRequest::new))); requests.add(new Tuple<>(SearchAction.NAME, new SearchRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7)))); requests.add(new Tuple<>(TermVectorsAction.NAME, - new TermVectorsRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7), "type", "id"))); + new TermVectorsRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7), "id"))); requests.add( new Tuple<>(GetAction.NAME, new GetRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7), "type", "id"))); requests.add(new Tuple<>(TermVectorsAction.NAME, - new TermVectorsRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7), "type", "id"))); + new TermVectorsRequest(randomFrom(SECURITY_MAIN_ALIAS, INTERNAL_SECURITY_MAIN_INDEX_7), "id"))); requests.add(new Tuple<>(IndicesAliasesAction.NAME, new IndicesAliasesRequest() .addAliasAction(AliasActions.add().alias("security_alias").index(INTERNAL_SECURITY_MAIN_INDEX_7)))); requests.add(new Tuple<>(ClusterHealthAction.NAME, @@ -1244,7 +1244,7 @@ private static Tuple randomCompositeRequest() { case 1: return Tuple.tuple(MultiSearchAction.NAME, new MultiSearchRequest().add(new SearchRequest())); case 2: - return Tuple.tuple(MultiTermVectorsAction.NAME, new MultiTermVectorsRequest().add("index", "type", "id")); + return Tuple.tuple(MultiTermVectorsAction.NAME, new MultiTermVectorsRequest().add("index", "id")); case 3: return Tuple.tuple(BulkAction.NAME, new BulkRequest().add(new DeleteRequest("index", "type", "id"))); case 4: diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java index b50ff864392a1..fe67224d5d824 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java @@ -374,13 +374,13 @@ public void testMultiGet() { public void testTermVectors() { createIndicesWithRandomAliases("test1", "index1"); - client().prepareTermVectors("test1", "type", "id").get(); + client().prepareTermVectors("test1", "id").get(); - assertThrowsAuthorizationExceptionDefaultUsers(client().prepareTermVectors("index1", "type", "id")::get, TermVectorsAction.NAME); + assertThrowsAuthorizationExceptionDefaultUsers(client().prepareTermVectors("index1", "id")::get, TermVectorsAction.NAME); - assertThrowsAuthorizationExceptionDefaultUsers(client().prepareTermVectors("missing", "type", "id")::get, TermVectorsAction.NAME); + assertThrowsAuthorizationExceptionDefaultUsers(client().prepareTermVectors("missing", "id")::get, TermVectorsAction.NAME); - expectThrows(IndexNotFoundException.class, () -> client().prepareTermVectors("test5", "type", "id").get()); + expectThrows(IndexNotFoundException.class, () -> client().prepareTermVectors("test5", "id").get()); } public void testMultiTermVectors() { From f753e8b16e13930dda01ed6c7442912bbf444ec6 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Mon, 20 May 2019 11:30:21 +0100 Subject: [PATCH 2/3] Addresses test failures and review comments --- .../documentation/CRUDDocumentationIT.java | 4 +- .../termvectors/TermVectorsRequest.java | 2 +- .../termvectors/MultiTermVectorsIT.java | 2 +- .../termvectors/TermVectorsUnitTests.java | 50 +++++++++++++++++++ .../routing/SimpleRoutingIT.java | 6 +-- .../search/morelikethis/MoreLikeThisIT.java | 4 +- .../security/authz/ReadActionsTests.java | 10 ++-- 7 files changed, 64 insertions(+), 14 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java index d430d05b7ea2b..ed3094d2f0bba 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java @@ -1614,8 +1614,8 @@ public void testTermVectors() throws Exception { // tag::term-vectors-response String index = response.getIndex(); // <1> - String id = response.getId(); // <3> - boolean found = response.getFound(); // <4> + String id = response.getId(); // <2> + boolean found = response.getFound(); // <3> // end::term-vectors-response if (response.getTermVectorsList() != null) { diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java index 317dfd65d6b18..0cf5f78f17a5e 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java @@ -494,7 +494,7 @@ public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); if (out.getVersion().before(Version.V_8_0_0)) { // types not supported so send an empty array to previous versions - out.writeString(null); + out.writeString("_doc"); } out.writeString(id); diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java b/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java index 9521c882929c9..964ac56692b9a 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java @@ -84,7 +84,7 @@ public void testMultiTermVectorsWithVersion() throws Exception { .setSettings(Settings.builder().put("index.refresh_interval", -1))); ensureGreen(); - MultiTermVectorsResponse response = client().prepareMultiTermVectors().add(indexOrAlias(), "type1", "1").get(); + MultiTermVectorsResponse response = client().prepareMultiTermVectors().add(indexOrAlias(), "1").get(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getResponse().isExists(), equalTo(false)); diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java b/server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java index ec5a5a8e40999..06d3fbf67f87d 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java @@ -36,6 +36,7 @@ import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; +import org.elasticsearch.Version; import org.elasticsearch.action.termvectors.TermVectorsRequest.Flag; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -48,7 +49,9 @@ import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.TextFieldMapper; import org.elasticsearch.index.mapper.TypeParsers; +import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.action.document.RestTermVectorsAction; +import org.elasticsearch.tasks.TaskId; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.StreamsUtils; import org.hamcrest.Matchers; @@ -258,6 +261,53 @@ public void testStreamRequest() throws IOException { } } + public void testStreamRequestLegacyVersion() throws IOException { + for (int i = 0; i < 10; i++) { + TermVectorsRequest request = new TermVectorsRequest("index", "id"); + request.offsets(random().nextBoolean()); + request.fieldStatistics(random().nextBoolean()); + request.payloads(random().nextBoolean()); + request.positions(random().nextBoolean()); + request.termStatistics(random().nextBoolean()); + String pref = random().nextBoolean() ? "somePreference" : null; + request.preference(pref); + request.doc(new BytesArray("{}"), randomBoolean(), XContentType.JSON); + + // write using older version which contains types + ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); + OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer); + out.setVersion(Version.V_7_2_0); + request.writeTo(out); + + // First check the type on the stream was written as "_doc" by manually parsing the stream until the type + ByteArrayInputStream esInBuffer = new ByteArrayInputStream(outBuffer.toByteArray()); + InputStreamStreamInput esBuffer = new InputStreamStreamInput(esInBuffer); + TaskId.readFromStream(esBuffer); + if (esBuffer.readBoolean()) { + new ShardId(esBuffer); + } + esBuffer.readOptionalString(); + assertThat(esBuffer.readString(), equalTo("_doc")); + + // now read the stream as normal to check it is parsed correct if received from an older node + esInBuffer = new ByteArrayInputStream(outBuffer.toByteArray()); + esBuffer = new InputStreamStreamInput(esInBuffer); + esBuffer.setVersion(Version.V_7_2_0); + TermVectorsRequest req2 = new TermVectorsRequest(null, null); + req2.readFrom(esBuffer); + + assertThat(request.offsets(), equalTo(req2.offsets())); + assertThat(request.fieldStatistics(), equalTo(req2.fieldStatistics())); + assertThat(request.payloads(), equalTo(req2.payloads())); + assertThat(request.positions(), equalTo(req2.positions())); + assertThat(request.termStatistics(), equalTo(req2.termStatistics())); + assertThat(request.preference(), equalTo(pref)); + assertThat(request.routing(), equalTo(null)); + assertEquals(new BytesArray("{}"), request.doc()); + assertEquals(XContentType.JSON, request.xContentType()); + } + } + public void testFieldTypeToTermVectorString() throws Exception { FieldType ft = new FieldType(); ft.setStoreTermVectorOffsets(false); diff --git a/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java b/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java index 34e754f915bfa..38ed0b819d4ab 100644 --- a/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java +++ b/server/src/test/java/org/elasticsearch/routing/SimpleRoutingIT.java @@ -594,7 +594,7 @@ public void testRequiredRoutingMappingVariousAPIs() throws Exception { client().prepareTermVectors(indexOrAlias(), "1").get(); fail(); } catch (RoutingMissingException e) { - assertThat(e.getMessage(), equalTo("routing is required for [test]/[1]")); + assertThat(e.getMessage(), equalTo("routing is required for [test]/[_doc]/[1]")); } UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1").setRouting(routingValue) @@ -654,14 +654,14 @@ public void testRequiredRoutingMappingVariousAPIs() throws Exception { assertThat(multiTermVectorsResponse.getResponses()[0].isFailed(), equalTo(true)); assertThat(multiTermVectorsResponse.getResponses()[0].getFailure() .getCause() - .getMessage(), equalTo("routing is required for [test]/[type1]/[1]")); + .getMessage(), equalTo("routing is required for [test]/[_doc]/[1]")); assertThat(multiTermVectorsResponse.getResponses()[0].getResponse(), nullValue()); assertThat(multiTermVectorsResponse.getResponses()[1].getId(), equalTo("2")); assertThat(multiTermVectorsResponse.getResponses()[1].isFailed(), equalTo(true)); assertThat(multiTermVectorsResponse.getResponses()[1].getResponse(), nullValue()); assertThat(multiTermVectorsResponse.getResponses()[1].getFailure() .getCause() - .getMessage(), equalTo("routing is required for [test]/[type1]/[2]")); + .getMessage(), equalTo("routing is required for [test]/[_doc]/[2]")); } private static String indexOrAlias() { diff --git a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java index 02d31f6ba26ab..3270dcc6212fc 100644 --- a/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java +++ b/server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java @@ -753,7 +753,7 @@ public void testWithMissingRouting() throws IOException { Throwable cause = exception.getCause(); assertThat(cause, instanceOf(RoutingMissingException.class)); - assertThat(cause.getMessage(), equalTo("routing is required for [test]/[1]")); + assertThat(cause.getMessage(), equalTo("routing is required for [test]/[_doc]/[1]")); } { @@ -767,7 +767,7 @@ public void testWithMissingRouting() throws IOException { Throwable cause = exception.getCause(); assertThat(cause, instanceOf(RoutingMissingException.class)); - assertThat(cause.getMessage(), equalTo("routing is required for [test]/[type1]/[2]")); + assertThat(cause.getMessage(), equalTo("routing is required for [test]/[_doc]/[2]")); } } } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java index fe67224d5d824..cb908f74aee79 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java @@ -386,11 +386,11 @@ public void testTermVectors() { public void testMultiTermVectors() { createIndicesWithRandomAliases("test1", "test2", "test3", "index1"); MultiTermVectorsResponse response = client().prepareMultiTermVectors() - .add("test1", "type", "id") - .add("index1", "type", "id") - .add("test3", "type", "id") - .add("missing", "type", "id") - .add("test5", "type", "id").get(); + .add("test1", "id") + .add("index1", "id") + .add("test3", "id") + .add("missing", "id") + .add("test5", "id").get(); assertEquals(5, response.getResponses().length); assertFalse(response.getResponses()[0].isFailed()); assertEquals("test1", response.getResponses()[0].getResponse().getIndex()); From 1c5c45dd48e6854abdabfc86c8e9f3e8fa3d5b42 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Tue, 4 Jun 2019 14:26:55 +0100 Subject: [PATCH 3/3] fixes indent --- .../java/org/elasticsearch/index/engine/FrozenIndexTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java index 98f67d6718be4..aabd52172af72 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java @@ -135,7 +135,7 @@ public void testSearchAndGetAPIsAreThrottled() throws InterruptedException, IOEx numRefreshes += 3; break; case 2: - client().prepareTermVectors("index", "" + randomIntBetween(0, 9)).execute(listener); + client().prepareTermVectors("index", "" + randomIntBetween(0, 9)).execute(listener); break; case 3: client().prepareExplain("index", "_doc", "" + randomIntBetween(0, 9)).setQuery(new MatchAllQueryBuilder())