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

Elastic8.14.0 #1264

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jdk:

before_install:
- sudo rm -rf /var/lib/elasticsearch
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.0-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.14.0-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
- sudo cp ./src/test/resources/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
- sudo cat /etc/elasticsearch/elasticsearch.yml
- sudo java -version
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.nlpcn</groupId>
<artifactId>elasticsearch-sql</artifactId>
<version>8.13.0.0</version>
<version>8.14.0.0</version>
<packaging>jar</packaging>
<description>Query elasticsearch using SQL</description>
<name>elasticsearch-sql</name>
Expand Down Expand Up @@ -44,7 +44,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<runSuite>**/MainTestSuite.class</runSuite>
<elasticsearch.plugin.name>sql</elasticsearch.plugin.name>
<elasticsearch.version>8.13.0</elasticsearch.version>
<elasticsearch.version>8.14.0</elasticsearch.version>
<elasticsearch.plugin.classname>org.elasticsearch.plugin.nlpcn.SqlPlug</elasticsearch.plugin.classname>
<druid.version>1.2.15</druid.version>
<guava.version>32.0.0-jre</guava.version>
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/org/elasticsearch/action/ParsedDocWriteResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.action;

import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;

import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;

/**
* A base class for the response of a write operation that involves a single doc
*/
public abstract class ParsedDocWriteResponse {

/**
* Parse the output of the {@link #innerToXContent(XContentBuilder, Params)} method.
*
* This method is intended to be called by subclasses and must be called multiple times to parse all the information concerning
* {@link DocWriteResponse} objects. It always parses the current token, updates the given parsing context accordingly
* if needed and then immediately returns.
*/
public static void parseInnerToXContent(XContentParser parser, DocWriteResponse.Builder context) throws IOException {
XContentParser.Token token = parser.currentToken();
ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser);

String currentFieldName = parser.currentName();
token = parser.nextToken();

if (token.isValue()) {
if (DocWriteResponse._INDEX.equals(currentFieldName)) {
// index uuid and shard id are unknown and can't be parsed back for now.
context.setShardId(new ShardId(new Index(parser.text(), IndexMetadata.INDEX_UUID_NA_VALUE), -1));
} else if (DocWriteResponse._ID.equals(currentFieldName)) {
context.setId(parser.text());
} else if (DocWriteResponse._VERSION.equals(currentFieldName)) {
context.setVersion(parser.longValue());
} else if (DocWriteResponse.RESULT.equals(currentFieldName)) {
String result = parser.text();
for (DocWriteResponse.Result r : DocWriteResponse.Result.values()) {
if (r.getLowercase().equals(result)) {
context.setResult(r);
break;
}
}
} else if (DocWriteResponse.FORCED_REFRESH.equals(currentFieldName)) {
context.setForcedRefresh(parser.booleanValue());
} else if (DocWriteResponse._SEQ_NO.equals(currentFieldName)) {
context.setSeqNo(parser.longValue());
} else if (DocWriteResponse._PRIMARY_TERM.equals(currentFieldName)) {
context.setPrimaryTerm(parser.longValue());
}
} else if (token == XContentParser.Token.START_OBJECT) {
if (DocWriteResponse._SHARDS.equals(currentFieldName)) {
context.setShardInfo(DocWriteResponse.ShardInfo.fromXContent(parser));
} else {
parser.skipChildren(); // skip potential inner objects for forward compatibility
}
} else if (token == XContentParser.Token.START_ARRAY) {
parser.skipChildren(); // skip potential inner arrays for forward compatibility
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.action.admin.cluster.settings;

import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.XContentParser;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;

/**
* A response for a cluster update settings action.
*/
public class ParsedClusterUpdateSettingsResponse {

private static final ConstructingObjectParser<ClusterUpdateSettingsResponse, Void> PARSER = new ConstructingObjectParser<>(
"cluster_update_settings_response",
true,
args -> {
return new ClusterUpdateSettingsResponse((boolean) args[0], (Settings) args[1], (Settings) args[2]);
}
);

static {
AcknowledgedResponse.declareAcknowledgedField(PARSER);
PARSER.declareObject(constructorArg(), (p, c) -> Settings.fromXContent(p), ClusterUpdateSettingsResponse.TRANSIENT);
PARSER.declareObject(constructorArg(), (p, c) -> Settings.fromXContent(p), ClusterUpdateSettingsResponse.PERSISTENT);
}

public static ClusterUpdateSettingsResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@

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

import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.BaseBroadcastResponse;
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentParser;

import java.util.Arrays;
import java.util.List;

import static org.elasticsearch.action.support.broadcast.BaseBroadcastResponse.declareBroadcastFields;
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;

/**
* The response of a refresh action.
*/
public class ParsedRefreshResponse {

private static final ParseField _SHARDS_FIELD = new ParseField("_shards");
private static final ParseField TOTAL_FIELD = new ParseField("total");
private static final ParseField SUCCESSFUL_FIELD = new ParseField("successful");
private static final ParseField FAILED_FIELD = new ParseField("failed");
private static final ParseField FAILURES_FIELD = new ParseField("failures");

private static final ConstructingObjectParser<BroadcastResponse, Void> PARSER = new ConstructingObjectParser<>("refresh", true, arg -> {
BaseBroadcastResponse response = (BaseBroadcastResponse) arg[0];
return new BroadcastResponse(
Expand All @@ -39,4 +49,25 @@ public class ParsedRefreshResponse {
public static BroadcastResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

/**
* {@link BaseBroadcastResponse#declareBroadcastFields(ConstructingObjectParser)}
*/
@SuppressWarnings("unchecked")
public static <T extends BaseBroadcastResponse> void declareBroadcastFields(ConstructingObjectParser<T, Void> PARSER) {
ConstructingObjectParser<BaseBroadcastResponse, Void> shardsParser = new ConstructingObjectParser<>(
"_shards",
true,
arg -> new BaseBroadcastResponse((int) arg[0], (int) arg[1], (int) arg[2], (List<DefaultShardOperationFailedException>) arg[3])
);
shardsParser.declareInt(constructorArg(), TOTAL_FIELD);
shardsParser.declareInt(constructorArg(), SUCCESSFUL_FIELD);
shardsParser.declareInt(constructorArg(), FAILED_FIELD);
shardsParser.declareObjectArray(
optionalConstructorArg(),
(p, c) -> DefaultShardOperationFailedException.fromXContent(p),
FAILURES_FIELD
);
PARSER.declareObject(constructorArg(), shardsParser, _SHARDS_FIELD);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import org.elasticsearch.action.DocWriteRequest.OpType;
import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.delete.ParsedDeleteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.index.ParsedIndexResponse;
import org.elasticsearch.action.update.ParsedUpdateResponse;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.core.CheckedConsumer;
import org.elasticsearch.rest.RestStatus;
Expand Down Expand Up @@ -54,17 +57,17 @@ public static BulkItemResponse fromXContent(XContentParser parser, int id) throw
if (opType == OpType.INDEX || opType == OpType.CREATE) {
final IndexResponse.Builder indexResponseBuilder = new IndexResponse.Builder();
builder = indexResponseBuilder;
itemParser = (indexParser) -> IndexResponse.parseXContentFields(indexParser, indexResponseBuilder);
itemParser = (indexParser) -> ParsedIndexResponse.parseXContentFields(indexParser, indexResponseBuilder);

} else if (opType == OpType.UPDATE) {
final UpdateResponse.Builder updateResponseBuilder = new UpdateResponse.Builder();
builder = updateResponseBuilder;
itemParser = (updateParser) -> UpdateResponse.parseXContentFields(updateParser, updateResponseBuilder);
itemParser = (updateParser) -> ParsedUpdateResponse.parseXContentFields(updateParser, updateResponseBuilder);

} else if (opType == OpType.DELETE) {
final DeleteResponse.Builder deleteResponseBuilder = new DeleteResponse.Builder();
builder = deleteResponseBuilder;
itemParser = (deleteParser) -> DeleteResponse.parseXContentFields(deleteParser, deleteResponseBuilder);
itemParser = (deleteParser) -> ParsedDeleteResponse.parseXContentFields(deleteParser, deleteResponseBuilder);
} else {
throwUnknownField(currentFieldName, parser);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.action.delete;

import org.elasticsearch.action.ParsedDocWriteResponse;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;

import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;

/**
* The response of the delete action.
*
* @see org.elasticsearch.action.delete.DeleteRequest
* @see org.elasticsearch.client.internal.Client#delete(DeleteRequest)
*/
public class ParsedDeleteResponse {

public static DeleteResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);

DeleteResponse.Builder context = new DeleteResponse.Builder();
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
parseXContentFields(parser, context);
}
return context.build();
}

/**
* Parse the current token and update the parsing context appropriately.
*/
public static void parseXContentFields(XContentParser parser, DeleteResponse.Builder context) throws IOException {
ParsedDocWriteResponse.parseInnerToXContent(parser, context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.action.index;

import org.elasticsearch.action.ParsedDocWriteResponse;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;

import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;

/**
* A response of an index operation,
*
* @see org.elasticsearch.action.index.IndexRequest
* @see org.elasticsearch.client.internal.Client#index(IndexRequest)
*/
public class ParsedIndexResponse {

public static IndexResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);

IndexResponse.Builder context = new IndexResponse.Builder();
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
parseXContentFields(parser, context);
}
return context.build();
}

/**
* Parse the current token and update the parsing context appropriately.
*/
public static void parseXContentFields(XContentParser parser, IndexResponse.Builder context) throws IOException {
ParsedDocWriteResponse.parseInnerToXContent(parser, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import org.elasticsearch.core.RefCounted;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.rest.action.RestActions;
import org.elasticsearch.search.ParsedSearchHits;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.profile.ParsedSearchProfileResults;
import org.elasticsearch.search.profile.SearchProfileResults;
import org.elasticsearch.search.suggest.ParsedSuggest;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParser.Token;
Expand Down Expand Up @@ -91,13 +94,13 @@ public static SearchResponse innerFromXContent(XContentParser parser) throws IOE
}
} else if (token == Token.START_OBJECT) {
if (SearchHits.Fields.HITS.equals(currentFieldName)) {
hits = SearchHits.fromXContent(parser);
hits = ParsedSearchHits.fromXContent(parser);
} else if (InternalAggregations.AGGREGATIONS_FIELD.equals(currentFieldName)) {
aggs = InternalAggregations.fromXContent(parser);
} else if (Suggest.NAME.equals(currentFieldName)) {
suggest = Suggest.fromXContent(parser);
suggest = ParsedSuggest.fromXContent(parser);
} else if (SearchProfileResults.PROFILE_FIELD.equals(currentFieldName)) {
profile = SearchProfileResults.fromXContent(parser);
profile = ParsedSearchProfileResults.fromXContent(parser);
} else if (RestActions._SHARDS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
while ((token = parser.nextToken()) != Token.END_OBJECT) {
if (token == Token.FIELD_NAME) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.action.update;

import org.elasticsearch.action.ParsedDocWriteResponse;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;

import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;

public class ParsedUpdateResponse {

public static UpdateResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);

UpdateResponse.Builder context = new UpdateResponse.Builder();
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
parseXContentFields(parser, context);
}
return context.build();
}

/**
* Parse the current token and update the parsing context appropriately.
*/
public static void parseXContentFields(XContentParser parser, UpdateResponse.Builder context) throws IOException {
XContentParser.Token token = parser.currentToken();
String currentFieldName = parser.currentName();

if (UpdateResponse.GET.equals(currentFieldName)) {
if (token == XContentParser.Token.START_OBJECT) {
context.setGetResult(GetResult.fromXContentEmbedded(parser));
}
} else {
ParsedDocWriteResponse.parseInnerToXContent(parser, context);
}
}
}
Loading