Skip to content

Commit 6d99eb9

Browse files
committed
Refactor an ambigious TermVectorsRequest constructor. (#35614)
1 parent d47ccac commit 6d99eb9

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/core/TermVectorsRequest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class TermVectorsRequest implements ToXContentObject, Validatable {
3333
private final String index;
3434
private final String type;
3535
private String id = null;
36+
private XContentBuilder docBuilder = null;
37+
3638
private String routing = null;
3739
private String preference = null;
3840
private boolean realtime = true;
@@ -44,7 +46,6 @@ public class TermVectorsRequest implements ToXContentObject, Validatable {
4446
private boolean requestTermStatistics = false;
4547
private Map<String, String> perFieldAnalyzer = null;
4648
private Map<String, Integer> filterSettings = null;
47-
private XContentBuilder docBuilder = null;
4849

4950

5051
/**
@@ -54,18 +55,21 @@ public class TermVectorsRequest implements ToXContentObject, Validatable {
5455
* @param docId - id of the document
5556
*/
5657
public TermVectorsRequest(String index, String type, String docId) {
57-
this(index, type);
58+
this.index = index;
59+
this.type = type;
5860
this.id = docId;
5961
}
6062

6163
/**
6264
* Constructs TermVectorRequest for an artificial document
6365
* @param index - index of the document
6466
* @param type - type of the document
67+
* @param docBuilder - an artificial document
6568
*/
66-
public TermVectorsRequest(String index, String type) {
69+
public TermVectorsRequest(String index, String type, XContentBuilder docBuilder) {
6770
this.index = index;
6871
this.type = type;
72+
this.docBuilder = docBuilder;
6973
}
7074

7175
/**

client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ public void testExists() throws IOException {
202202
highLevelClient()::exists, highLevelClient()::existsAsync));
203203
}
204204
}
205-
206-
public void testSourceExists() throws IOException {
205+
206+
public void testSourceExists() throws IOException {
207207
{
208208
GetRequest getRequest = new GetRequest("index", "type", "id");
209209
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
@@ -225,17 +225,17 @@ public void testSourceExists() throws IOException {
225225
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
226226
}
227227
}
228-
229-
public void testSourceDoesNotExist() throws IOException {
228+
229+
public void testSourceDoesNotExist() throws IOException {
230230
final String noSourceIndex = "no_source";
231231
{
232232
// Prepare
233233
Settings settings = Settings.builder()
234234
.put("number_of_shards", 1)
235235
.put("number_of_replicas", 0)
236236
.build();
237-
String mapping = "\"_doc\": { \"_source\": {\n" +
238-
" \"enabled\": false\n" +
237+
String mapping = "\"_doc\": { \"_source\": {\n" +
238+
" \"enabled\": false\n" +
239239
" } }";
240240
createIndex(noSourceIndex, settings, mapping);
241241
assertEquals(
@@ -250,13 +250,13 @@ public void testSourceDoesNotExist() throws IOException {
250250
RequestOptions.DEFAULT
251251
).status()
252252
);
253-
}
253+
}
254254
{
255255
GetRequest getRequest = new GetRequest(noSourceIndex, "_doc", "1");
256256
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
257257
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
258258
}
259-
}
259+
}
260260

261261
public void testGet() throws IOException {
262262
{
@@ -1221,10 +1221,10 @@ public void testTermvectors() throws IOException {
12211221
}
12221222
{
12231223
// test _termvectors on artificial documents
1224-
TermVectorsRequest tvRequest = new TermVectorsRequest(sourceIndex, "_doc");
12251224
XContentBuilder docBuilder = XContentFactory.jsonBuilder();
12261225
docBuilder.startObject().field("field", "valuex").endObject();
1227-
tvRequest.setDoc(docBuilder);
1226+
1227+
TermVectorsRequest tvRequest = new TermVectorsRequest(sourceIndex, "_doc", docBuilder);
12281228
TermVectorsResponse tvResponse = execute(tvRequest, highLevelClient()::termvectors, highLevelClient()::termvectorsAsync);
12291229

12301230
TermVectorsResponse.TermVector.Token expectedToken = new TermVectorsResponse.TermVector.Token(0, 6, 0, null);

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,10 +1561,12 @@ public void testTermVectors() throws Exception {
15611561

15621562
{
15631563
// tag::term-vectors-request-artificial
1564-
TermVectorsRequest request = new TermVectorsRequest("authors", "_doc");
1564+
15651565
XContentBuilder docBuilder = XContentFactory.jsonBuilder();
15661566
docBuilder.startObject().field("user", "guest-user").endObject();
1567-
request.setDoc(docBuilder); // <1>
1567+
TermVectorsRequest request = new TermVectorsRequest("authors",
1568+
"_doc",
1569+
docBuilder); // <1>
15681570
// end::term-vectors-request-artificial
15691571

15701572
// tag::term-vectors-request-optional-arguments

0 commit comments

Comments
 (0)