Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes type from TermVectors APIs #42198

Merged
merged 3 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<TermVector> termVectorList;

public TermVectorsResponse(
String index, String type, String id, long version, boolean found, long tookInMillis, List<TermVector> termVectorList) {
public TermVectorsResponse(String index, String id, long version, boolean found, long tookInMillis, List<TermVector> termVectorList) {
this.index = index;
this.type = type;
this.id = id;
this.docVersion = version;
this.found = found;
Expand All @@ -53,26 +50,24 @@ public TermVectorsResponse(

private static ConstructingObjectParser<TermVectorsResponse, Void> 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<TermVector> termVectorList = (List<TermVector>) args[6];
// as the response comes from server, we are sure that args[5] will be a list of TermVector
@SuppressWarnings("unchecked") List<TermVector> termVectorList = (List<TermVector>) 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
);
}
);

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"));
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -1614,9 +1614,8 @@ 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>
String id = response.getId(); // <2>
boolean found = response.getFound(); // <3>
// end::term-vectors-response

if (response.getTermVectorsList() != null) {
Expand Down
7 changes: 3 additions & 4 deletions docs/java-rest/high-level/document/term-vectors.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions docs/reference/docs/termvectors.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ Response:
{
"_id": "1",
"_index": "twitter",
"_type": "_doc",
"_version": 1,
"found": true,
"took": 6,
Expand Down Expand Up @@ -344,7 +343,6 @@ Response:
--------------------------------------------------
{
"_index": "twitter",
"_type": "_doc",
"_version": 0,
"found": true,
"took": 6,
Expand Down Expand Up @@ -415,7 +413,6 @@ Response:
--------------------------------------------------
{
"_index": "imdb",
"_type": "_doc",
"_version": 0,
"found": true,
"term_vectors": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@
like:
-
_index: test_1
_type: _doc
doc:
foo: bar
-
_index: test_1
_type: _doc
_id: 2
-
_id: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"docs":
-
"_index" : "testidx"
"_type" : "_doc"
"_id" : "testing_document"
"version" : 1
"_version_type" : "external"
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
realtime: false

- match: { _index: "testidx" }
- match: { _type: "_doc" }
- match: { _id: "1" }
- is_false: found
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@

import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.Nullable;

public class MultiTermVectorsRequestBuilder extends ActionRequestBuilder<MultiTermVectorsRequest, MultiTermVectorsResponse> {

public MultiTermVectorsRequestBuilder(ElasticsearchClient client, MultiTermVectorsAction action) {
super(client, action, new MultiTermVectorsRequest());
}

public MultiTermVectorsRequestBuilder add(String index, @Nullable String type, Iterable<String> ids) {
public MultiTermVectorsRequestBuilder add(String index, Iterable<String> 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;
}
Expand Down
Loading