use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class XContentSettingsLoader method load.
public Map<String, String> load(XContentParser jp) throws IOException {
StringBuilder sb = new StringBuilder();
Map<String, String> settings = new HashMap<>();
List<String> path = new ArrayList<>();
XContentParser.Token token = jp.nextToken();
if (token == null) {
return settings;
}
if (token != XContentParser.Token.START_OBJECT) {
throw new ElasticsearchParseException("malformed, expected settings to start with 'object', instead was [{}]", token);
}
serializeObject(settings, sb, path, jp, null);
// ensure we reached the end of the stream
XContentParser.Token lastToken = null;
try {
while (!jp.isClosed() && (lastToken = jp.nextToken()) == null) ;
} catch (Exception e) {
throw new ElasticsearchParseException("malformed, expected end of settings but encountered additional content starting at line number: [{}], " + "column number: [{}]", e, jp.getTokenLocation().lineNumber, jp.getTokenLocation().columnNumber);
}
if (lastToken != null) {
throw new ElasticsearchParseException("malformed, expected end of settings but encountered additional content starting at line number: [{}], " + "column number: [{}]", jp.getTokenLocation().lineNumber, jp.getTokenLocation().columnNumber);
}
return settings;
}
use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class ConfigurationUtils method newConfigurationException.
public static ElasticsearchException newConfigurationException(String processorType, String processorTag, String propertyName, String reason) {
String msg;
if (propertyName == null) {
msg = reason;
} else {
msg = "[" + propertyName + "] " + reason;
}
ElasticsearchParseException exception = new ElasticsearchParseException(msg);
addHeadersToException(exception, processorType, processorTag, propertyName);
return exception;
}
use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class RestRequest method contentOrSourceParamParser.
/**
* A parser for the contents of this request if it has contents, otherwise a parser for the {@code source} parameter if there is one,
* otherwise throws an {@link ElasticsearchParseException}. Use {@link #withContentOrSourceParamParserOrNull(CheckedConsumer)} instead
* if you need to handle the absence request content gracefully.
*/
public final XContentParser contentOrSourceParamParser() throws IOException {
Tuple<XContentType, BytesReference> tuple = contentOrSourceParam();
BytesReference content = tuple.v2();
if (content.length() == 0) {
throw new ElasticsearchParseException("Body required");
}
return tuple.v1().xContent().createParser(xContentRegistry, content);
}
use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class GeoDistanceSortBuilder method parseGeoPoints.
static void parseGeoPoints(XContentParser parser, List<GeoPoint> geoPoints) throws IOException {
while (!parser.nextToken().equals(XContentParser.Token.END_ARRAY)) {
if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) {
// we might get here if the geo point is " number, number] " and the parser already moved over the
// opening bracket in this case we cannot use GeoUtils.parseGeoPoint(..) because this expects an opening
// bracket
double lon = parser.doubleValue();
parser.nextToken();
if (!parser.currentToken().equals(XContentParser.Token.VALUE_NUMBER)) {
throw new ElasticsearchParseException("geo point parsing: expected second number but got [{}] instead", parser.currentToken());
}
double lat = parser.doubleValue();
GeoPoint point = new GeoPoint();
point.reset(lat, lon);
geoPoints.add(point);
} else {
GeoPoint point = new GeoPoint();
GeoUtils.parseGeoPoint(parser, point);
geoPoints.add(point);
}
}
}
use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class GeoDistanceSortBuilder method build.
@Override
public SortFieldAndFormat build(QueryShardContext context) throws IOException {
final boolean indexCreatedBeforeV2_0 = context.indexVersionCreated().before(Version.V_2_0_0);
// validation was not available prior to 2.x, so to support bwc percolation queries we only ignore_malformed
// on 2.x created indexes
GeoPoint[] localPoints = points.toArray(new GeoPoint[points.size()]);
if (!indexCreatedBeforeV2_0 && !GeoValidationMethod.isIgnoreMalformed(validation)) {
for (GeoPoint point : localPoints) {
if (GeoUtils.isValidLatitude(point.lat()) == false) {
throw new ElasticsearchParseException("illegal latitude value [{}] for [GeoDistanceSort] for field [{}].", point.lat(), fieldName);
}
if (GeoUtils.isValidLongitude(point.lon()) == false) {
throw new ElasticsearchParseException("illegal longitude value [{}] for [GeoDistanceSort] for field [{}].", point.lon(), fieldName);
}
}
}
if (GeoValidationMethod.isCoerce(validation)) {
for (GeoPoint point : localPoints) {
GeoUtils.normalizePoint(point, true, true);
}
}
boolean reverse = (order == SortOrder.DESC);
final MultiValueMode finalSortMode;
if (sortMode == null) {
finalSortMode = reverse ? MultiValueMode.MAX : MultiValueMode.MIN;
} else {
finalSortMode = MultiValueMode.fromString(sortMode.toString());
}
MappedFieldType fieldType = context.fieldMapper(fieldName);
if (fieldType == null) {
throw new IllegalArgumentException("failed to find mapper for [" + fieldName + "] for geo distance based sort");
}
final IndexGeoPointFieldData geoIndexFieldData = context.getForField(fieldType);
final Nested nested = resolveNested(context, nestedPath, nestedFilter);
if (// only works with 5.x geo_point
geoIndexFieldData.getClass() == LatLonPointDVIndexFieldData.class && nested == null && // LatLonDocValuesField internally picks the closest point
finalSortMode == MultiValueMode.MIN && unit == DistanceUnit.METERS && reverse == false && localPoints.length == 1) {
return new SortFieldAndFormat(LatLonDocValuesField.newDistanceSort(fieldName, localPoints[0].lat(), localPoints[0].lon()), DocValueFormat.RAW);
}
IndexFieldData.XFieldComparatorSource geoDistanceComparatorSource = new IndexFieldData.XFieldComparatorSource() {
@Override
public SortField.Type reducedType() {
return SortField.Type.DOUBLE;
}
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) {
return new FieldComparator.DoubleComparator(numHits, null, null) {
@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
final MultiGeoPointValues geoPointValues = geoIndexFieldData.load(context).getGeoPointValues();
final SortedNumericDoubleValues distanceValues = GeoUtils.distanceValues(geoDistance, unit, geoPointValues, localPoints);
final NumericDoubleValues selectedValues;
if (nested == null) {
selectedValues = finalSortMode.select(distanceValues, Double.POSITIVE_INFINITY);
} else {
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
selectedValues = finalSortMode.select(distanceValues, Double.POSITIVE_INFINITY, rootDocs, innerDocs, context.reader().maxDoc());
}
return selectedValues.getRawDoubleValues();
}
};
}
};
return new SortFieldAndFormat(new SortField(fieldName, geoDistanceComparatorSource, reverse), DocValueFormat.RAW);
}
Aggregations