Skip to content
Permalink
Browse files

Standardize underscore requirements in parameters

Stardardize underscore requirements in parameters across different type of
requests:
_index, _type, _source, _id keep their underscores
params like version and retry_on_conflict will be without underscores

BulkRequest, MultiGetRequest, TermVectorcRequest, MoreLikeThisQuery were
changed

Closes elastic#26886
  • Loading branch information
mayya-sharipova committed Oct 18, 2017
1 parent df5c8bb commit a6078d82e3e540659bbd9818f61425316ee9dfb7
@@ -191,23 +191,23 @@ static Request bulk(BulkRequest bulkRequest) throws IOException {
metadata.field("_id", request.id());
}
if (Strings.hasLength(request.routing())) {
metadata.field("_routing", request.routing());
metadata.field("routing", request.routing());
}
if (Strings.hasLength(request.parent())) {
metadata.field("_parent", request.parent());
metadata.field("parent", request.parent());
}
if (request.version() != Versions.MATCH_ANY) {
metadata.field("_version", request.version());
metadata.field("version", request.version());
}

VersionType versionType = request.versionType();
if (versionType != VersionType.INTERNAL) {
if (versionType == VersionType.EXTERNAL) {
metadata.field("_version_type", "external");
metadata.field("version_type", "external");
} else if (versionType == VersionType.EXTERNAL_GTE) {
metadata.field("_version_type", "external_gte");
metadata.field("version_type", "external_gte");
} else if (versionType == VersionType.FORCE) {
metadata.field("_version_type", "force");
metadata.field("version_type", "force");
}
}

@@ -219,7 +219,7 @@ static Request bulk(BulkRequest bulkRequest) throws IOException {
} else if (opType == DocWriteRequest.OpType.UPDATE) {
UpdateRequest updateRequest = (UpdateRequest) request;
if (updateRequest.retryOnConflict() > 0) {
metadata.field("_retry_on_conflict", updateRequest.retryOnConflict());
metadata.field("retry_on_conflict", updateRequest.retryOnConflict());
}
if (updateRequest.fetchSource() != null) {
metadata.field("_source", updateRequest.fetchSource());
@@ -30,6 +30,7 @@
import org.elasticsearch.action.support.replication.ReplicationRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
@@ -68,6 +69,19 @@

private static final int REQUEST_OVERHEAD = 50;

private static final ParseField INDEX = new ParseField("_index");
private static final ParseField TYPE = new ParseField("_type");
private static final ParseField ID = new ParseField("_id");
private static final ParseField ROUTING = new ParseField("routing", "_routing");
private static final ParseField PARENT = new ParseField("parent", "_parent");
private static final ParseField OP_TYPE = new ParseField("op_type", "opType");
private static final ParseField VERSION = new ParseField("version", "_version");
private static final ParseField VERSION_TYPE = new ParseField("version_type", "_version_type", "_versionType", "versionType");
private static final ParseField RETRY_ON_CONFLICT = new ParseField("retry_on_conflict", "_retry_on_conflict", "_retryOnConflict");
private static final ParseField PIPELINE = new ParseField("pipeline");
private static final ParseField FIELDS = new ParseField("fields");
private static final ParseField SOURCE = new ParseField("_source");

/**
* Requests that are part of this request. It is only possible to add things that are both {@link ActionRequest}s and
* {@link WriteRequest}s to this but java doesn't support syntax to declare that everything in the array has both types so we declare
@@ -334,45 +348,45 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if ("_index".equals(currentFieldName)) {
if (INDEX.match(currentFieldName)){
if (!allowExplicitIndex) {
throw new IllegalArgumentException("explicit index in bulk is not allowed");
}
index = parser.text();
} else if ("_type".equals(currentFieldName)) {
} else if (TYPE.match(currentFieldName)) {
type = parser.text();
} else if ("_id".equals(currentFieldName)) {
} else if (ID.match(currentFieldName)) {
id = parser.text();
} else if ("_routing".equals(currentFieldName) || "routing".equals(currentFieldName)) {
} else if (ROUTING.match(currentFieldName)) {
routing = parser.text();
} else if ("_parent".equals(currentFieldName) || "parent".equals(currentFieldName)) {
} else if (PARENT.match(currentFieldName)) {
parent = parser.text();
} else if ("op_type".equals(currentFieldName) || "opType".equals(currentFieldName)) {
} else if (OP_TYPE.match(currentFieldName)) {
opType = parser.text();
} else if ("_version".equals(currentFieldName) || "version".equals(currentFieldName)) {
} else if (VERSION.match(currentFieldName)) {
version = parser.longValue();
} else if ("_version_type".equals(currentFieldName) || "_versionType".equals(currentFieldName) || "version_type".equals(currentFieldName) || "versionType".equals(currentFieldName)) {
} else if (VERSION_TYPE.match(currentFieldName)) {
versionType = VersionType.fromString(parser.text());
} else if ("_retry_on_conflict".equals(currentFieldName) || "_retryOnConflict".equals(currentFieldName)) {
} else if (RETRY_ON_CONFLICT.match(currentFieldName)) {
retryOnConflict = parser.intValue();
} else if ("pipeline".equals(currentFieldName)) {
} else if (PIPELINE.match(currentFieldName)) {
pipeline = parser.text();
} else if ("fields".equals(currentFieldName)) {
} else if (FIELDS.match(currentFieldName)) {
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains a simple value for parameter [fields] while a list is expected");
} else if ("_source".equals(currentFieldName)) {
} else if (SOURCE.match(currentFieldName)) {
fetchSourceContext = FetchSourceContext.fromXContent(parser);
} else {
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + currentFieldName + "]");
}
} else if (token == XContentParser.Token.START_ARRAY) {
if ("fields".equals(currentFieldName)) {
if (FIELDS.match(currentFieldName)) {
DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
List<Object> values = parser.list();
fields = values.toArray(new String[values.size()]);
} else {
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
}
} else if (token == XContentParser.Token.START_OBJECT && "_source".equals(currentFieldName)) {
} else if (token == XContentParser.Token.START_OBJECT && SOURCE.match(currentFieldName)) {
fetchSourceContext = FetchSourceContext.fromXContent(parser);
} else if (token != XContentParser.Token.VALUE_NULL) {
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
@@ -28,6 +28,7 @@
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
@@ -48,6 +49,17 @@

public class MultiGetRequest extends ActionRequest implements Iterable<MultiGetRequest.Item>, CompositeIndicesRequest, RealtimeRequest {

private static final ParseField INDEX = new ParseField("_index");
private static final ParseField TYPE = new ParseField("_type");
private static final ParseField ID = new ParseField("_id");
private static final ParseField ROUTING = new ParseField("routing", "_routing");
private static final ParseField PARENT = new ParseField("parent", "_parent");
private static final ParseField VERSION = new ParseField("version", "_version");
private static final ParseField VERSION_TYPE = new ParseField("version_type", "_version_type", "_versionType", "versionType");
private static final ParseField FIELDS = new ParseField("fields");
private static final ParseField STORED_FIELDS = new ParseField("stored_fields");
private static final ParseField SOURCE = new ParseField("_source");

/**
* A single get item.
*/
@@ -379,30 +391,30 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if ("_index".equals(currentFieldName)) {
if (INDEX.match(currentFieldName)) {
if (!allowExplicitIndex) {
throw new IllegalArgumentException("explicit index in multi get is not allowed");
}
index = parser.text();
} else if ("_type".equals(currentFieldName)) {
} else if (TYPE.match(currentFieldName)) {
type = parser.text();
} else if ("_id".equals(currentFieldName)) {
} else if (ID.match(currentFieldName)) {
id = parser.text();
} else if ("_routing".equals(currentFieldName) || "routing".equals(currentFieldName)) {
} else if (ROUTING.match(currentFieldName)) {
routing = parser.text();
} else if ("_parent".equals(currentFieldName) || "parent".equals(currentFieldName)) {
} else if (PARENT.match(currentFieldName)) {
parent = parser.text();
} else if ("fields".equals(currentFieldName)) {
} else if (FIELDS.match(currentFieldName)) {
throw new ParsingException(parser.getTokenLocation(),
"Unsupported field [fields] used, expected [stored_fields] instead");
} else if ("stored_fields".equals(currentFieldName)) {
} else if (STORED_FIELDS.match(currentFieldName)) {
storedFields = new ArrayList<>();
storedFields.add(parser.text());
} else if ("_version".equals(currentFieldName) || "version".equals(currentFieldName)) {
} else if (VERSION.match(currentFieldName)) {
version = parser.longValue();
} else if ("_version_type".equals(currentFieldName) || "_versionType".equals(currentFieldName) || "version_type".equals(currentFieldName) || "versionType".equals(currentFieldName)) {
} else if (VERSION_TYPE.match(currentFieldName)) {
versionType = VersionType.fromString(parser.text());
} else if ("_source".equals(currentFieldName)) {
} else if (SOURCE.match(currentFieldName)) {
// check lenient to avoid interpreting the value as string but parse strict in order to provoke an error early on.
if (parser.isBooleanValueLenient()) {
fetchSourceContext = new FetchSourceContext(parser.booleanValue(), fetchSourceContext.includes(),
@@ -415,15 +427,15 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
}
}
} else if (token == XContentParser.Token.START_ARRAY) {
if ("fields".equals(currentFieldName)) {
if (FIELDS.match(currentFieldName)) {
throw new ParsingException(parser.getTokenLocation(),
"Unsupported field [fields] used, expected [stored_fields] instead");
} else if ("stored_fields".equals(currentFieldName)) {
} else if (STORED_FIELDS.match(currentFieldName)) {
storedFields = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
storedFields.add(parser.text());
}
} else if ("_source".equals(currentFieldName)) {
} else if (SOURCE.match(currentFieldName)) {
ArrayList<String> includes = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
includes.add(parser.text());
@@ -433,7 +445,7 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
}

} else if (token == XContentParser.Token.START_OBJECT) {
if ("_source".equals(currentFieldName)) {
if (SOURCE.match(currentFieldName)) {
List<String> currentList = null, includes = null, excludes = null;

while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {

0 comments on commit a6078d8

Please sign in to comment.
You can’t perform that action at this time.