Skip to content

Commit b370dc5

Browse files
committed
es 8.14.0 support
1 parent 7bf6431 commit b370dc5

22 files changed

+1152
-18
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jdk:
55

66
before_install:
77
- sudo rm -rf /var/lib/elasticsearch
8-
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.4-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
8+
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.14.0-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
99
- sudo cp ./src/test/resources/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
1010
- sudo cat /etc/elasticsearch/elasticsearch.yml
1111
- sudo java -version

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.nlpcn</groupId>
55
<artifactId>elasticsearch-sql</artifactId>
6-
<version>8.13.4.0</version>
6+
<version>8.14.0.0</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>
@@ -44,7 +44,7 @@
4444
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4545
<runSuite>**/MainTestSuite.class</runSuite>
4646
<elasticsearch.plugin.name>sql</elasticsearch.plugin.name>
47-
<elasticsearch.version>8.13.4</elasticsearch.version>
47+
<elasticsearch.version>8.14.0</elasticsearch.version>
4848
<elasticsearch.plugin.classname>org.elasticsearch.plugin.nlpcn.SqlPlug</elasticsearch.plugin.classname>
4949
<druid.version>1.2.15</druid.version>
5050
<guava.version>32.0.0-jre</guava.version>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
package org.elasticsearch.action;
9+
10+
import org.elasticsearch.cluster.metadata.IndexMetadata;
11+
import org.elasticsearch.index.Index;
12+
import org.elasticsearch.index.shard.ShardId;
13+
import org.elasticsearch.xcontent.XContentBuilder;
14+
import org.elasticsearch.xcontent.XContentParser;
15+
16+
import java.io.IOException;
17+
18+
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
19+
20+
/**
21+
* A base class for the response of a write operation that involves a single doc
22+
*/
23+
public abstract class ParsedDocWriteResponse {
24+
25+
/**
26+
* Parse the output of the {@link #innerToXContent(XContentBuilder, Params)} method.
27+
*
28+
* This method is intended to be called by subclasses and must be called multiple times to parse all the information concerning
29+
* {@link DocWriteResponse} objects. It always parses the current token, updates the given parsing context accordingly
30+
* if needed and then immediately returns.
31+
*/
32+
public static void parseInnerToXContent(XContentParser parser, DocWriteResponse.Builder context) throws IOException {
33+
XContentParser.Token token = parser.currentToken();
34+
ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser);
35+
36+
String currentFieldName = parser.currentName();
37+
token = parser.nextToken();
38+
39+
if (token.isValue()) {
40+
if (DocWriteResponse._INDEX.equals(currentFieldName)) {
41+
// index uuid and shard id are unknown and can't be parsed back for now.
42+
context.setShardId(new ShardId(new Index(parser.text(), IndexMetadata.INDEX_UUID_NA_VALUE), -1));
43+
} else if (DocWriteResponse._ID.equals(currentFieldName)) {
44+
context.setId(parser.text());
45+
} else if (DocWriteResponse._VERSION.equals(currentFieldName)) {
46+
context.setVersion(parser.longValue());
47+
} else if (DocWriteResponse.RESULT.equals(currentFieldName)) {
48+
String result = parser.text();
49+
for (DocWriteResponse.Result r : DocWriteResponse.Result.values()) {
50+
if (r.getLowercase().equals(result)) {
51+
context.setResult(r);
52+
break;
53+
}
54+
}
55+
} else if (DocWriteResponse.FORCED_REFRESH.equals(currentFieldName)) {
56+
context.setForcedRefresh(parser.booleanValue());
57+
} else if (DocWriteResponse._SEQ_NO.equals(currentFieldName)) {
58+
context.setSeqNo(parser.longValue());
59+
} else if (DocWriteResponse._PRIMARY_TERM.equals(currentFieldName)) {
60+
context.setPrimaryTerm(parser.longValue());
61+
}
62+
} else if (token == XContentParser.Token.START_OBJECT) {
63+
if (DocWriteResponse._SHARDS.equals(currentFieldName)) {
64+
context.setShardInfo(DocWriteResponse.ShardInfo.fromXContent(parser));
65+
} else {
66+
parser.skipChildren(); // skip potential inner objects for forward compatibility
67+
}
68+
} else if (token == XContentParser.Token.START_ARRAY) {
69+
parser.skipChildren(); // skip potential inner arrays for forward compatibility
70+
}
71+
}
72+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.action.admin.cluster.settings;
10+
11+
import org.elasticsearch.action.support.master.AcknowledgedResponse;
12+
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.xcontent.ConstructingObjectParser;
14+
import org.elasticsearch.xcontent.XContentParser;
15+
16+
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
17+
18+
/**
19+
* A response for a cluster update settings action.
20+
*/
21+
public class ParsedClusterUpdateSettingsResponse {
22+
23+
private static final ConstructingObjectParser<ClusterUpdateSettingsResponse, Void> PARSER = new ConstructingObjectParser<>(
24+
"cluster_update_settings_response",
25+
true,
26+
args -> {
27+
return new ClusterUpdateSettingsResponse((boolean) args[0], (Settings) args[1], (Settings) args[2]);
28+
}
29+
);
30+
31+
static {
32+
AcknowledgedResponse.declareAcknowledgedField(PARSER);
33+
PARSER.declareObject(constructorArg(), (p, c) -> Settings.fromXContent(p), ClusterUpdateSettingsResponse.TRANSIENT);
34+
PARSER.declareObject(constructorArg(), (p, c) -> Settings.fromXContent(p), ClusterUpdateSettingsResponse.PERSISTENT);
35+
}
36+
37+
public static ClusterUpdateSettingsResponse fromXContent(XContentParser parser) {
38+
return PARSER.apply(parser, null);
39+
}
40+
}

src/main/java/org/elasticsearch/action/admin/indices/refresh/ParsedRefreshResponse.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,30 @@
88

99
package org.elasticsearch.action.admin.indices.refresh;
1010

11+
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
1112
import org.elasticsearch.action.support.broadcast.BaseBroadcastResponse;
1213
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
1314
import org.elasticsearch.xcontent.ConstructingObjectParser;
15+
import org.elasticsearch.xcontent.ParseField;
1416
import org.elasticsearch.xcontent.XContentParser;
1517

1618
import java.util.Arrays;
19+
import java.util.List;
1720

18-
import static org.elasticsearch.action.support.broadcast.BaseBroadcastResponse.declareBroadcastFields;
21+
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
22+
import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;
1923

2024
/**
2125
* The response of a refresh action.
2226
*/
2327
public class ParsedRefreshResponse {
2428

29+
private static final ParseField _SHARDS_FIELD = new ParseField("_shards");
30+
private static final ParseField TOTAL_FIELD = new ParseField("total");
31+
private static final ParseField SUCCESSFUL_FIELD = new ParseField("successful");
32+
private static final ParseField FAILED_FIELD = new ParseField("failed");
33+
private static final ParseField FAILURES_FIELD = new ParseField("failures");
34+
2535
private static final ConstructingObjectParser<BroadcastResponse, Void> PARSER = new ConstructingObjectParser<>("refresh", true, arg -> {
2636
BaseBroadcastResponse response = (BaseBroadcastResponse) arg[0];
2737
return new BroadcastResponse(
@@ -39,4 +49,25 @@ public class ParsedRefreshResponse {
3949
public static BroadcastResponse fromXContent(XContentParser parser) {
4050
return PARSER.apply(parser, null);
4151
}
52+
53+
/**
54+
* {@link BaseBroadcastResponse#declareBroadcastFields(ConstructingObjectParser)}
55+
*/
56+
@SuppressWarnings("unchecked")
57+
public static <T extends BaseBroadcastResponse> void declareBroadcastFields(ConstructingObjectParser<T, Void> PARSER) {
58+
ConstructingObjectParser<BaseBroadcastResponse, Void> shardsParser = new ConstructingObjectParser<>(
59+
"_shards",
60+
true,
61+
arg -> new BaseBroadcastResponse((int) arg[0], (int) arg[1], (int) arg[2], (List<DefaultShardOperationFailedException>) arg[3])
62+
);
63+
shardsParser.declareInt(constructorArg(), TOTAL_FIELD);
64+
shardsParser.declareInt(constructorArg(), SUCCESSFUL_FIELD);
65+
shardsParser.declareInt(constructorArg(), FAILED_FIELD);
66+
shardsParser.declareObjectArray(
67+
optionalConstructorArg(),
68+
(p, c) -> DefaultShardOperationFailedException.fromXContent(p),
69+
FAILURES_FIELD
70+
);
71+
PARSER.declareObject(constructorArg(), shardsParser, _SHARDS_FIELD);
72+
}
4273
}

src/main/java/org/elasticsearch/action/bulk/ParsedBulkItemResponse.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import org.elasticsearch.action.DocWriteRequest.OpType;
1313
import org.elasticsearch.action.DocWriteResponse;
1414
import org.elasticsearch.action.delete.DeleteResponse;
15+
import org.elasticsearch.action.delete.ParsedDeleteResponse;
1516
import org.elasticsearch.action.index.IndexResponse;
17+
import org.elasticsearch.action.index.ParsedIndexResponse;
18+
import org.elasticsearch.action.update.ParsedUpdateResponse;
1619
import org.elasticsearch.action.update.UpdateResponse;
1720
import org.elasticsearch.core.CheckedConsumer;
1821
import org.elasticsearch.rest.RestStatus;
@@ -54,17 +57,17 @@ public static BulkItemResponse fromXContent(XContentParser parser, int id) throw
5457
if (opType == OpType.INDEX || opType == OpType.CREATE) {
5558
final IndexResponse.Builder indexResponseBuilder = new IndexResponse.Builder();
5659
builder = indexResponseBuilder;
57-
itemParser = (indexParser) -> IndexResponse.parseXContentFields(indexParser, indexResponseBuilder);
60+
itemParser = (indexParser) -> ParsedIndexResponse.parseXContentFields(indexParser, indexResponseBuilder);
5861

5962
} else if (opType == OpType.UPDATE) {
6063
final UpdateResponse.Builder updateResponseBuilder = new UpdateResponse.Builder();
6164
builder = updateResponseBuilder;
62-
itemParser = (updateParser) -> UpdateResponse.parseXContentFields(updateParser, updateResponseBuilder);
65+
itemParser = (updateParser) -> ParsedUpdateResponse.parseXContentFields(updateParser, updateResponseBuilder);
6366

6467
} else if (opType == OpType.DELETE) {
6568
final DeleteResponse.Builder deleteResponseBuilder = new DeleteResponse.Builder();
6669
builder = deleteResponseBuilder;
67-
itemParser = (deleteParser) -> DeleteResponse.parseXContentFields(deleteParser, deleteResponseBuilder);
70+
itemParser = (deleteParser) -> ParsedDeleteResponse.parseXContentFields(deleteParser, deleteResponseBuilder);
6871
} else {
6972
throwUnknownField(currentFieldName, parser);
7073
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.action.delete;
10+
11+
import org.elasticsearch.action.ParsedDocWriteResponse;
12+
import org.elasticsearch.xcontent.XContentParser;
13+
14+
import java.io.IOException;
15+
16+
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
17+
18+
/**
19+
* The response of the delete action.
20+
*
21+
* @see org.elasticsearch.action.delete.DeleteRequest
22+
* @see org.elasticsearch.client.internal.Client#delete(DeleteRequest)
23+
*/
24+
public class ParsedDeleteResponse {
25+
26+
public static DeleteResponse fromXContent(XContentParser parser) throws IOException {
27+
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
28+
29+
DeleteResponse.Builder context = new DeleteResponse.Builder();
30+
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
31+
parseXContentFields(parser, context);
32+
}
33+
return context.build();
34+
}
35+
36+
/**
37+
* Parse the current token and update the parsing context appropriately.
38+
*/
39+
public static void parseXContentFields(XContentParser parser, DeleteResponse.Builder context) throws IOException {
40+
ParsedDocWriteResponse.parseInnerToXContent(parser, context);
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.action.index;
10+
11+
import org.elasticsearch.action.ParsedDocWriteResponse;
12+
import org.elasticsearch.xcontent.XContentParser;
13+
14+
import java.io.IOException;
15+
16+
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
17+
18+
/**
19+
* A response of an index operation,
20+
*
21+
* @see org.elasticsearch.action.index.IndexRequest
22+
* @see org.elasticsearch.client.internal.Client#index(IndexRequest)
23+
*/
24+
public class ParsedIndexResponse {
25+
26+
public static IndexResponse fromXContent(XContentParser parser) throws IOException {
27+
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
28+
29+
IndexResponse.Builder context = new IndexResponse.Builder();
30+
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
31+
parseXContentFields(parser, context);
32+
}
33+
return context.build();
34+
}
35+
36+
/**
37+
* Parse the current token and update the parsing context appropriately.
38+
*/
39+
public static void parseXContentFields(XContentParser parser, IndexResponse.Builder context) throws IOException {
40+
ParsedDocWriteResponse.parseInnerToXContent(parser, context);
41+
}
42+
}

src/main/java/org/elasticsearch/action/search/ParsedSearchResponse.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
import org.elasticsearch.core.RefCounted;
1313
import org.elasticsearch.core.TimeValue;
1414
import org.elasticsearch.rest.action.RestActions;
15+
import org.elasticsearch.search.ParsedSearchHits;
1516
import org.elasticsearch.search.SearchHits;
1617
import org.elasticsearch.search.aggregations.InternalAggregations;
18+
import org.elasticsearch.search.profile.ParsedSearchProfileResults;
1719
import org.elasticsearch.search.profile.SearchProfileResults;
20+
import org.elasticsearch.search.suggest.ParsedSuggest;
1821
import org.elasticsearch.search.suggest.Suggest;
1922
import org.elasticsearch.xcontent.XContentParser;
2023
import org.elasticsearch.xcontent.XContentParser.Token;
@@ -91,13 +94,13 @@ public static SearchResponse innerFromXContent(XContentParser parser) throws IOE
9194
}
9295
} else if (token == Token.START_OBJECT) {
9396
if (SearchHits.Fields.HITS.equals(currentFieldName)) {
94-
hits = SearchHits.fromXContent(parser);
97+
hits = ParsedSearchHits.fromXContent(parser);
9598
} else if (InternalAggregations.AGGREGATIONS_FIELD.equals(currentFieldName)) {
9699
aggs = InternalAggregations.fromXContent(parser);
97100
} else if (Suggest.NAME.equals(currentFieldName)) {
98-
suggest = Suggest.fromXContent(parser);
101+
suggest = ParsedSuggest.fromXContent(parser);
99102
} else if (SearchProfileResults.PROFILE_FIELD.equals(currentFieldName)) {
100-
profile = SearchProfileResults.fromXContent(parser);
103+
profile = ParsedSearchProfileResults.fromXContent(parser);
101104
} else if (RestActions._SHARDS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
102105
while ((token = parser.nextToken()) != Token.END_OBJECT) {
103106
if (token == Token.FIELD_NAME) {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.action.update;
10+
11+
import org.elasticsearch.action.ParsedDocWriteResponse;
12+
import org.elasticsearch.index.get.GetResult;
13+
import org.elasticsearch.xcontent.XContentParser;
14+
15+
import java.io.IOException;
16+
17+
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
18+
19+
public class ParsedUpdateResponse {
20+
21+
public static UpdateResponse fromXContent(XContentParser parser) throws IOException {
22+
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
23+
24+
UpdateResponse.Builder context = new UpdateResponse.Builder();
25+
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
26+
parseXContentFields(parser, context);
27+
}
28+
return context.build();
29+
}
30+
31+
/**
32+
* Parse the current token and update the parsing context appropriately.
33+
*/
34+
public static void parseXContentFields(XContentParser parser, UpdateResponse.Builder context) throws IOException {
35+
XContentParser.Token token = parser.currentToken();
36+
String currentFieldName = parser.currentName();
37+
38+
if (UpdateResponse.GET.equals(currentFieldName)) {
39+
if (token == XContentParser.Token.START_OBJECT) {
40+
context.setGetResult(GetResult.fromXContentEmbedded(parser));
41+
}
42+
} else {
43+
ParsedDocWriteResponse.parseInnerToXContent(parser, context);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)