Skip to content

Commit c98b772

Browse files
committed
Merge branch 'master' into disk-threshold-settings-validation
* master: Remove deprecated created and found from index, delete and bulk (elastic#25516) fix testEnsureVersionCompatibility for 5.5.0 release fix Version.v6_0_0 min compatibility version to 5.5.0 Add bwc indices for 5.5.0 Add v5_5_1 constant [DOCS] revise high level client Search Scroll API docs (elastic#25599) Improve REST error handling when endpoint does not support HTTP verb, add OPTIONS support (elastic#24437) Avoid SecurityException in repository-S3 on DefaultS3OutputStream.flush() (elastic#25254) [Tests] Add tests for CompletionSuggestionBuilder#build() (elastic#25575)
2 parents da177bf + 2ba9fd2 commit c98b772

File tree

33 files changed

+679
-200
lines changed

33 files changed

+679
-200
lines changed

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

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
import org.elasticsearch.rest.RestStatus;
3737
import org.elasticsearch.search.Scroll;
3838
import org.elasticsearch.search.SearchHit;
39+
import org.elasticsearch.search.SearchHits;
3940
import org.elasticsearch.search.builder.SearchSourceBuilder;
4041

4142
import java.io.IOException;
42-
import java.util.Arrays;
43+
import java.util.Collections;
4344
import java.util.List;
4445

4546
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
@@ -78,31 +79,37 @@ public void testScroll() throws IOException {
7879
assertFalse(bulkResponse.hasFailures());
7980
}
8081
{
81-
// tag::search-scroll-example
82-
final Scroll scroll = new Scroll(TimeValue.timeValueMinutes(1L)); // <1>
83-
84-
SearchRequest searchRequest = new SearchRequest("posts"); // <2>
85-
searchRequest.source(new SearchSourceBuilder().query(matchQuery("title", "Elasticsearch")));
86-
searchRequest.scroll(scroll); // <3>
87-
88-
SearchResponse searchResponse = client.search(searchRequest); // <4>
89-
String scrollId = searchResponse.getScrollId(); // <5>
90-
91-
SearchHit[] searchHits = searchResponse.getHits().getHits(); // <6>
92-
while (searchHits != null && searchHits.length > 0) { // <7>
93-
SearchScrollRequest scrollRequest = new SearchScrollRequest() // <8>
94-
.scroll(scroll) // <9>
95-
.scrollId(scrollId); // <10>
96-
97-
searchResponse = client.searchScroll(scrollRequest); // <11>
98-
scrollId = searchResponse.getScrollId(); // <12>
99-
searchHits = searchResponse.getHits().getHits(); // <13>
100-
}
101-
102-
ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); // <14>
82+
int size = 1;
83+
// tag::search-scroll-init
84+
SearchRequest searchRequest = new SearchRequest("posts");
85+
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
86+
searchSourceBuilder.query(matchQuery("title", "Elasticsearch"));
87+
searchSourceBuilder.size(size); // <1>
88+
searchRequest.source(searchSourceBuilder);
89+
searchRequest.scroll(TimeValue.timeValueMinutes(1L)); // <2>
90+
SearchResponse searchResponse = client.search(searchRequest);
91+
String scrollId = searchResponse.getScrollId(); // <3>
92+
SearchHits hits = searchResponse.getHits(); // <4>
93+
// end::search-scroll-init
94+
assertEquals(3, hits.getTotalHits());
95+
assertEquals(1, hits.getHits().length);
96+
assertNotNull(scrollId);
97+
98+
// tag::search-scroll2
99+
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); // <1>
100+
scrollRequest.scroll(TimeValue.timeValueSeconds(30));
101+
SearchResponse searchScrollResponse = client.searchScroll(scrollRequest);
102+
scrollId = searchScrollResponse.getScrollId(); // <2>
103+
hits = searchScrollResponse.getHits(); // <3>
104+
assertEquals(3, hits.getTotalHits());
105+
assertEquals(1, hits.getHits().length);
106+
assertNotNull(scrollId);
107+
// end::search-scroll2
108+
109+
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
103110
clearScrollRequest.addScrollId(scrollId);
104-
client.clearScroll(clearScrollRequest);
105-
// end::search-scroll-example
111+
ClearScrollResponse clearScrollResponse = client.clearScroll(clearScrollRequest);
112+
assertTrue(clearScrollResponse.isSucceeded());
106113
}
107114
{
108115
SearchRequest searchRequest = new SearchRequest();
@@ -114,10 +121,10 @@ public void testScroll() throws IOException {
114121
SearchScrollRequest scrollRequest = new SearchScrollRequest();
115122
scrollRequest.scrollId(scrollId);
116123

117-
// tag::scroll-request-scroll
124+
// tag::scroll-request-arguments
118125
scrollRequest.scroll(TimeValue.timeValueSeconds(60L)); // <1>
119126
scrollRequest.scroll("60s"); // <2>
120-
// end::scroll-request-scroll
127+
// end::scroll-request-arguments
121128

122129
// tag::search-scroll-execute-sync
123130
SearchResponse searchResponse = client.searchScroll(scrollRequest);
@@ -149,7 +156,7 @@ public void onFailure(Exception e) {
149156
request.addScrollId(scrollId);
150157
// end::clear-scroll-add-scroll-id
151158

152-
List<String> scrollIds = Arrays.asList(scrollId);
159+
List<String> scrollIds = Collections.singletonList(scrollId);
153160

154161
// tag::clear-scroll-add-scroll-ids
155162
request.setScrollIds(scrollIds);
@@ -180,5 +187,34 @@ public void onFailure(Exception e) {
180187
});
181188
// end::clear-scroll-execute-async
182189
}
190+
{
191+
// tag::search-scroll-example
192+
final Scroll scroll = new Scroll(TimeValue.timeValueMinutes(1L));
193+
SearchRequest searchRequest = new SearchRequest("posts");
194+
searchRequest.scroll(scroll);
195+
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
196+
searchSourceBuilder.query(matchQuery("title", "Elasticsearch"));
197+
searchRequest.source(searchSourceBuilder);
198+
199+
SearchResponse searchResponse = client.search(searchRequest); // <1>
200+
String scrollId = searchResponse.getScrollId();
201+
SearchHit[] searchHits = searchResponse.getHits().getHits();
202+
203+
while (searchHits != null && searchHits.length > 0) { // <2>
204+
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); // <3>
205+
scrollRequest.scroll(scroll);
206+
searchResponse = client.searchScroll(scrollRequest);
207+
scrollId = searchResponse.getScrollId();
208+
searchHits = searchResponse.getHits().getHits();
209+
// <4>
210+
}
211+
212+
ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); // <5>
213+
clearScrollRequest.addScrollId(scrollId);
214+
ClearScrollResponse clearScrollResponse = client.clearScroll(clearScrollRequest);
215+
boolean succeeded = clearScrollResponse.isSucceeded();
216+
// end::search-scroll-example
217+
assertTrue(succeeded);
218+
}
183219
}
184220
}

core/src/main/java/org/elasticsearch/Version.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public class Version implements Comparable<Version> {
8484
public static final Version V_5_4_3 = new Version(V_5_4_3_ID, org.apache.lucene.util.Version.LUCENE_6_5_1);
8585
public static final int V_5_5_0_ID = 5050099;
8686
public static final Version V_5_5_0 = new Version(V_5_5_0_ID, org.apache.lucene.util.Version.LUCENE_6_6_0);
87+
public static final int V_5_5_1_ID = 5050199;
88+
public static final Version V_5_5_1 = new Version(V_5_5_1_ID, org.apache.lucene.util.Version.LUCENE_6_6_0);
8789
public static final int V_5_6_0_ID = 5060099;
8890
public static final Version V_5_6_0 = new Version(V_5_6_0_ID, org.apache.lucene.util.Version.LUCENE_6_6_0);
8991
public static final int V_6_0_0_alpha1_ID = 6000001;
@@ -118,6 +120,8 @@ public static Version fromId(int id) {
118120
return V_6_0_0_alpha1;
119121
case V_5_6_0_ID:
120122
return V_5_6_0;
123+
case V_5_5_1_ID:
124+
return V_5_5_1;
121125
case V_5_5_0_ID:
122126
return V_5_5_0;
123127
case V_5_4_3_ID:
@@ -304,8 +308,8 @@ public Version minimumCompatibilityVersion() {
304308
final int bwcMajor;
305309
final int bwcMinor;
306310
if (major == 6) { // we only specialize for current major here
307-
bwcMajor = Version.V_5_4_0.major;
308-
bwcMinor = Version.V_5_4_0.minor;
311+
bwcMajor = Version.V_5_5_0.major;
312+
bwcMinor = Version.V_5_5_0.minor;
309313
} else if (major > 6) { // all the future versions are compatible with first minor...
310314
bwcMajor = major -1;
311315
bwcMinor = 0;

core/src/main/java/org/elasticsearch/action/delete/DeleteResponse.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.action.delete;
2121

2222
import org.elasticsearch.action.DocWriteResponse;
23-
import org.elasticsearch.common.xcontent.XContentBuilder;
2423
import org.elasticsearch.common.xcontent.XContentParser;
2524
import org.elasticsearch.index.shard.ShardId;
2625
import org.elasticsearch.rest.RestStatus;
@@ -37,8 +36,6 @@
3736
*/
3837
public class DeleteResponse extends DocWriteResponse {
3938

40-
private static final String FOUND = "found";
41-
4239
public DeleteResponse() {
4340
}
4441

@@ -64,13 +61,6 @@ public String toString() {
6461
return builder.append("]").toString();
6562
}
6663

67-
@Override
68-
public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException {
69-
builder.field(FOUND, result == Result.DELETED);
70-
super.innerToXContent(builder, params);
71-
return builder;
72-
}
73-
7464
public static DeleteResponse fromXContent(XContentParser parser) throws IOException {
7565
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
7666

@@ -85,16 +75,7 @@ public static DeleteResponse fromXContent(XContentParser parser) throws IOExcept
8575
* Parse the current token and update the parsing context appropriately.
8676
*/
8777
public static void parseXContentFields(XContentParser parser, Builder context) throws IOException {
88-
XContentParser.Token token = parser.currentToken();
89-
String currentFieldName = parser.currentName();
90-
91-
if (FOUND.equals(currentFieldName)) {
92-
if (token.isValue()) {
93-
context.setFound(parser.booleanValue());
94-
}
95-
} else {
96-
DocWriteResponse.parseInnerToXContent(parser, context);
97-
}
78+
DocWriteResponse.parseInnerToXContent(parser, context);
9879
}
9980

10081
/**
@@ -104,15 +85,10 @@ public static void parseXContentFields(XContentParser parser, Builder context) t
10485
*/
10586
public static class Builder extends DocWriteResponse.Builder {
10687

107-
private boolean found = false;
108-
109-
public void setFound(boolean found) {
110-
this.found = found;
111-
}
112-
11388
@Override
11489
public DeleteResponse build() {
115-
DeleteResponse deleteResponse = new DeleteResponse(shardId, type, id, seqNo, primaryTerm, version, found);
90+
DeleteResponse deleteResponse = new DeleteResponse(shardId, type, id, seqNo, primaryTerm, version,
91+
result == Result.DELETED ? true : false);
11692
deleteResponse.setForcedRefresh(forcedRefresh);
11793
if (shardInfo != null) {
11894
deleteResponse.setShardInfo(shardInfo);

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

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.elasticsearch.action.DocWriteResponse;
2323
import org.elasticsearch.common.Strings;
24-
import org.elasticsearch.common.xcontent.XContentBuilder;
2524
import org.elasticsearch.common.xcontent.XContentParser;
2625
import org.elasticsearch.index.shard.ShardId;
2726
import org.elasticsearch.rest.RestStatus;
@@ -38,8 +37,6 @@
3837
*/
3938
public class IndexResponse extends DocWriteResponse {
4039

41-
private static final String CREATED = "created";
42-
4340
public IndexResponse() {
4441
}
4542

@@ -67,13 +64,6 @@ public String toString() {
6764
return builder.append("]").toString();
6865
}
6966

70-
@Override
71-
public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException {
72-
super.innerToXContent(builder, params);
73-
builder.field(CREATED, result == Result.CREATED);
74-
return builder;
75-
}
76-
7767
public static IndexResponse fromXContent(XContentParser parser) throws IOException {
7868
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
7969

@@ -88,16 +78,7 @@ public static IndexResponse fromXContent(XContentParser parser) throws IOExcepti
8878
* Parse the current token and update the parsing context appropriately.
8979
*/
9080
public static void parseXContentFields(XContentParser parser, Builder context) throws IOException {
91-
XContentParser.Token token = parser.currentToken();
92-
String currentFieldName = parser.currentName();
93-
94-
if (CREATED.equals(currentFieldName)) {
95-
if (token.isValue()) {
96-
context.setCreated(parser.booleanValue());
97-
}
98-
} else {
99-
DocWriteResponse.parseInnerToXContent(parser, context);
100-
}
81+
DocWriteResponse.parseInnerToXContent(parser, context);
10182
}
10283

10384
/**
@@ -107,15 +88,10 @@ public static void parseXContentFields(XContentParser parser, Builder context) t
10788
*/
10889
public static class Builder extends DocWriteResponse.Builder {
10990

110-
private boolean created = false;
111-
112-
public void setCreated(boolean created) {
113-
this.created = created;
114-
}
115-
11691
@Override
11792
public IndexResponse build() {
118-
IndexResponse indexResponse = new IndexResponse(shardId, type, id, seqNo, primaryTerm, version, created);
93+
IndexResponse indexResponse = new IndexResponse(shardId, type, id, seqNo, primaryTerm, version,
94+
result == Result.CREATED ? true : false);
11995
indexResponse.setForcedRefresh(forcedRefresh);
12096
if (shardInfo != null) {
12197
indexResponse.setShardInfo(shardInfo);

0 commit comments

Comments
 (0)