Skip to content

Commit 4fea6b6

Browse files
authored
Refactor an ambigious TermVectorsRequest constructor. (#35614)
1 parent d62bbca commit 4fea6b6

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
@@ -192,8 +192,8 @@ public void testExists() throws IOException {
192192
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
193193
}
194194
}
195-
196-
public void testSourceExists() throws IOException {
195+
196+
public void testSourceExists() throws IOException {
197197
{
198198
GetRequest getRequest = new GetRequest("index", "type", "id");
199199
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
@@ -215,17 +215,17 @@ public void testSourceExists() throws IOException {
215215
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
216216
}
217217
}
218-
219-
public void testSourceDoesNotExist() throws IOException {
218+
219+
public void testSourceDoesNotExist() throws IOException {
220220
final String noSourceIndex = "no_source";
221221
{
222222
// Prepare
223223
Settings settings = Settings.builder()
224224
.put("number_of_shards", 1)
225225
.put("number_of_replicas", 0)
226226
.build();
227-
String mapping = "\"_doc\": { \"_source\": {\n" +
228-
" \"enabled\": false\n" +
227+
String mapping = "\"_doc\": { \"_source\": {\n" +
228+
" \"enabled\": false\n" +
229229
" } }";
230230
createIndex(noSourceIndex, settings, mapping);
231231
assertEquals(
@@ -240,13 +240,13 @@ public void testSourceDoesNotExist() throws IOException {
240240
RequestOptions.DEFAULT
241241
).status()
242242
);
243-
}
243+
}
244244
{
245245
GetRequest getRequest = new GetRequest(noSourceIndex, "_doc", "1");
246246
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
247247
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
248248
}
249-
}
249+
}
250250

251251
public void testGet() throws IOException {
252252
{
@@ -1154,10 +1154,10 @@ public void testTermvectors() throws IOException {
11541154
}
11551155
{
11561156
// test _termvectors on artificial documents
1157-
TermVectorsRequest tvRequest = new TermVectorsRequest(sourceIndex, "_doc");
11581157
XContentBuilder docBuilder = XContentFactory.jsonBuilder();
11591158
docBuilder.startObject().field("field", "valuex").endObject();
1160-
tvRequest.setDoc(docBuilder);
1159+
1160+
TermVectorsRequest tvRequest = new TermVectorsRequest(sourceIndex, "_doc", docBuilder);
11611161
TermVectorsResponse tvResponse = execute(tvRequest, highLevelClient()::termvectors, highLevelClient()::termvectorsAsync);
11621162

11631163
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
@@ -1565,10 +1565,12 @@ public void testTermVectors() throws Exception {
15651565

15661566
{
15671567
// tag::term-vectors-request-artificial
1568-
TermVectorsRequest request = new TermVectorsRequest("authors", "_doc");
1568+
15691569
XContentBuilder docBuilder = XContentFactory.jsonBuilder();
15701570
docBuilder.startObject().field("user", "guest-user").endObject();
1571-
request.setDoc(docBuilder); // <1>
1571+
TermVectorsRequest request = new TermVectorsRequest("authors",
1572+
"_doc",
1573+
docBuilder); // <1>
15721574
// end::term-vectors-request-artificial
15731575

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

0 commit comments

Comments
 (0)