use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.
the class ConfigurationUtils method newConfigurationException.
public static OpenSearchException newConfigurationException(String processorType, String processorTag, String propertyName, String reason) {
String msg;
if (propertyName == null) {
msg = reason;
} else {
msg = "[" + propertyName + "] " + reason;
}
OpenSearchParseException exception = new OpenSearchParseException(msg);
addMetadataToException(exception, processorType, processorTag, propertyName);
return exception;
}
use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.
the class GeoQueryContext method fromXContent.
public static GeoQueryContext fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token = parser.currentToken();
GeoQueryContext.Builder builder = new Builder();
if (token == XContentParser.Token.START_OBJECT) {
GEO_CONTEXT_PARSER.parse(parser, builder, null);
} else if (token == XContentParser.Token.VALUE_STRING) {
builder.setGeoPoint(GeoPoint.fromGeohash(parser.text()));
} else {
throw new OpenSearchParseException("geo context must be an object or string");
}
return builder.build();
}
use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.
the class SuggestionBuilder method fromXContent.
static SuggestionBuilder<?> fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token;
String currentFieldName = null;
String suggestText = null;
String prefix = null;
String regex = null;
SuggestionBuilder<?> suggestionBuilder = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if (TEXT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
suggestText = parser.text();
} else if (PREFIX_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
prefix = parser.text();
} else if (REGEX_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
regex = parser.text();
} else {
throw new ParsingException(parser.getTokenLocation(), "suggestion does not support [" + currentFieldName + "]");
}
} else if (token == XContentParser.Token.START_OBJECT) {
suggestionBuilder = parser.namedObject(SuggestionBuilder.class, currentFieldName, null);
}
}
if (suggestionBuilder == null) {
throw new OpenSearchParseException("missing suggestion object");
}
if (suggestText != null) {
suggestionBuilder.text(suggestText);
}
if (prefix != null) {
suggestionBuilder.prefix(prefix);
}
if (regex != null) {
suggestionBuilder.regex(regex);
}
return suggestionBuilder;
}
use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.
the class GeoBoundingBoxTests method testInvalidParsePoint.
public void testInvalidParsePoint() throws IOException {
XContentBuilder bboxBuilder = XContentFactory.jsonBuilder().startObject().field("wkt", "POINT (100.0 100.0)").endObject();
XContentParser parser = createParser(bboxBuilder);
parser.nextToken();
OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> GeoBoundingBox.parseBoundingBox(parser));
assertThat(e.getMessage(), equalTo("failed to parse WKT bounding box. [POINT] found. expected [ENVELOPE]"));
}
use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.
the class AllocationCommands method fromXContent.
/**
* Reads {@link AllocationCommands} from a {@link XContentParser}
* <pre>
* {
* "commands" : [
* {"allocate" : {"index" : "test", "shard" : 0, "node" : "test"}}
* ]
* }
* </pre>
* @param parser {@link XContentParser} to read the commands from
* @return {@link AllocationCommands} read
* @throws IOException if something bad happens while reading the stream
*/
public static AllocationCommands fromXContent(XContentParser parser) throws IOException {
AllocationCommands commands = new AllocationCommands();
XContentParser.Token token = parser.currentToken();
if (token == null) {
throw new OpenSearchParseException("No commands");
}
if (token == XContentParser.Token.FIELD_NAME) {
if (!parser.currentName().equals("commands")) {
throw new OpenSearchParseException("expected field name to be named [commands], got [{}] instead", parser.currentName());
}
token = parser.nextToken();
if (token != XContentParser.Token.START_ARRAY) {
throw new OpenSearchParseException("commands should follow with an array element");
}
} else if (token == XContentParser.Token.START_ARRAY) {
// ok...
} else {
throw new OpenSearchParseException("expected either field name [commands], or start array, got [{}] instead", token);
}
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
if (token == XContentParser.Token.START_OBJECT) {
// move to the command name
token = parser.nextToken();
String commandName = parser.currentName();
token = parser.nextToken();
commands.add(parser.namedObject(AllocationCommand.class, commandName, null));
// move to the end object one
if (parser.nextToken() != XContentParser.Token.END_OBJECT) {
throw new OpenSearchParseException("allocation command is malformed, done parsing a command," + " but didn't get END_OBJECT, got [{}] instead", token);
}
} else {
throw new OpenSearchParseException("allocation command is malformed, got [{}] instead", token);
}
}
return commands;
}
Aggregations