Search in sources :

Example 1 with ElasticsearchParseException

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;
}
Also used : HashMap(java.util.HashMap) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) ArrayList(java.util.ArrayList) XContentParser(org.elasticsearch.common.xcontent.XContentParser) IOException(java.io.IOException) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 2 with ElasticsearchParseException

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;
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 3 with ElasticsearchParseException

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);
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) XContentType(org.elasticsearch.common.xcontent.XContentType) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 4 with ElasticsearchParseException

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);
        }
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 5 with ElasticsearchParseException

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);
}
Also used : IndexGeoPointFieldData(org.elasticsearch.index.fielddata.IndexGeoPointFieldData) Nested(org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested) BitSet(org.apache.lucene.util.BitSet) SortField(org.apache.lucene.search.SortField) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) MultiValueMode(org.elasticsearch.search.MultiValueMode) GeoPoint(org.elasticsearch.common.geo.GeoPoint) LatLonPointDVIndexFieldData(org.elasticsearch.index.fielddata.plain.AbstractLatLonPointDVIndexFieldData.LatLonPointDVIndexFieldData) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) LatLonPointDVIndexFieldData(org.elasticsearch.index.fielddata.plain.AbstractLatLonPointDVIndexFieldData.LatLonPointDVIndexFieldData) IndexFieldData(org.elasticsearch.index.fielddata.IndexFieldData) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator)

Aggregations

ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)106 XContentParser (org.elasticsearch.common.xcontent.XContentParser)44 HashMap (java.util.HashMap)28 ArrayList (java.util.ArrayList)18 IOException (java.io.IOException)13 Map (java.util.Map)11 List (java.util.List)7 GeoPoint (org.elasticsearch.common.geo.GeoPoint)7 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 ParsingException (org.elasticsearch.common.ParsingException)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)4 Version (org.elasticsearch.Version)4 NoNodeAvailableException (org.elasticsearch.client.transport.NoNodeAvailableException)4 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)4 UncheckedIOException (java.io.UncheckedIOException)3 LinkedHashSet (java.util.LinkedHashSet)3 PutPipelineRequest (org.elasticsearch.action.ingest.PutPipelineRequest)3