Package org.elasticsearch

Examples of org.elasticsearch.ElasticSearchParseException


    public ContextConfig parseContext(ParseContext parseContext, XContentParser parser) throws IOException, ElasticsearchParseException {

        if(fieldName != null) {
            FieldMapper<?> mapper = parseContext.docMapper().mappers().fullName(fieldName).mapper();
            if(!(mapper instanceof GeoPointFieldMapper)) {
                throw new ElasticsearchParseException("referenced field must be mapped to geo_point");
            }
        }
       
        Collection<String> locations;
        if(parser.currentToken() == Token.VALUE_NULL) {
View Full Code Here


                return parser.intValue();
            default:
                return GeoUtils.geoHashLevelsForPrecision(parser.doubleValue());
            }
        default:
            throw new ElasticsearchParseException("invalid precision value");
        }
    }
View Full Code Here

                            case VALUE_NUMBER:
                            case VALUE_STRING:
                                lat = parser.doubleValue(true);
                                break;
                            default:
                                throw new ElasticsearchParseException("latitude must be a number");
                        }
                    } else {
                        throw new ElasticsearchParseException("only lat/lon or [" + FIELD_VALUE + "] is allowed");
                    }
                } else if ("lon".equals(fieldName)) {
                    if(point == null) {
                        parser.nextToken();
                        switch (parser.currentToken()) {
                            case VALUE_NUMBER:
                            case VALUE_STRING:
                                lon = parser.doubleValue(true);
                                break;
                            default:
                                throw new ElasticsearchParseException("longitude must be a number");
                        }
                    } else {
                        throw new ElasticsearchParseException("only lat/lon or [" + FIELD_VALUE + "] is allowed");
                    }
                } else if (FIELD_PRECISION.equals(fieldName)) {
                    if(parser.nextToken() == Token.START_ARRAY) {
                        IntOpenHashSet precisions = new IntOpenHashSet();
                        while(parser.nextToken() != Token.END_ARRAY) {
                            precisions.add(parsePrecision(parser));
                        }
                        precision = precisions.toArray();
                    } else {
                        precision = new int[] { parsePrecision(parser) };
                    }
                } else if (FIELD_VALUE.equals(fieldName)) {
                    if(Double.isNaN(lon) && Double.isNaN(lat)) {
                        parser.nextToken();
                        point = GeoUtils.parseGeoPoint(parser);
                    } else {
                        throw new ElasticsearchParseException("only lat/lon or [" + FIELD_VALUE + "] is allowed");
                    }
                } else {
                    throw new ElasticsearchParseException("unexpected fieldname [" + fieldName + "]");
                }
            }

            if (point == null) {
                if (Double.isNaN(lat) || Double.isNaN(lon)) {
                    throw new ElasticsearchParseException("location is missing");
                } else {
                    point = new GeoPoint(lat, lon);
                }
            }
View Full Code Here

    @Override
    public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
        builder.startObject("_geo_distance");
        if (geohashes.size() == 0 && points.size() == 0) {
            throw new ElasticsearchParseException("No points provided for _geo_distance sort.");
        }

        builder.startArray(fieldName);
        for (GeoPoint point : points) {
            builder.value(point);
View Full Code Here

        if (sValue.endsWith("%")) {
            final String percentAsString = sValue.substring(0, sValue.length() - 1);
            try {
                final double percent = Double.parseDouble(percentAsString);
                if (percent < 0 || percent > 100) {
                    throw new ElasticsearchParseException("Percentage should be in [0-100], got " + percentAsString);
                }
                return new RatioValue(Math.abs(percent));
            } catch (NumberFormatException e) {
                throw new ElasticsearchParseException("Failed to parse [" + percentAsString + "] as a double", e);
            }
        } else {
            try {
                double ratio = Double.parseDouble(sValue);
                if (ratio < 0 || ratio > 1.0) {
                    throw new ElasticsearchParseException("Ratio should be in [0-1.0], got " + ratio);
                }
                return new RatioValue(100.0 * Math.abs(ratio));
            } catch (NumberFormatException e) {
                throw new ElasticsearchParseException("Invalid ratio or percentage: [" + sValue + "]");
            }

        }
    }
View Full Code Here

            } else {
                millis = Long.parseLong(sValue);
            }
            return new TimeValue(millis, TimeUnit.MILLISECONDS);
        } catch (NumberFormatException e) {
            throw new ElasticsearchParseException("Failed to parse [" + sValue + "]", e);
        }
    }
View Full Code Here

                singles = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 1)) * SizeUnit.C5);
            } else {
                singles = Long.parseLong(sValue);
            }
        } catch (NumberFormatException e) {
            throw new ElasticsearchParseException("Failed to parse [" + sValue + "]", e);
        }
        return new SizeValue(singles, SizeUnit.SINGLE);
    }
View Full Code Here

                Tuple<XContentType, Map<String, Object>> tuple = sourceAsMapAndType(source);
                this.sourceContentType = tuple.v1();
                this.source = tuple.v2();
            }
        } catch (Exception e) {
            throw new ElasticsearchParseException("failed to parse / load source", e);
        }
        return this.source;
    }
View Full Code Here

            try {
                reader.document(docId, fieldVisitor);
                fieldVisitor.postProcess(data.mapper());
                data.fields(ImmutableMap.of(name, fieldVisitor.fields().get(data.mapper().names().indexName())));
            } catch (IOException e) {
                throw new ElasticsearchParseException("failed to load field [" + name + "]", e);
            }
        }
        return data;
    }
View Full Code Here

                        while (p.nextToken() != XContentParser.Token.END_ARRAY) {
                            percentiles.add(p.doubleValue());
                        }
                        builder.setPercentiles(Doubles.toArray(percentiles));
                    } else {
                        throw new ElasticsearchParseException("Failed parsing array field [" + fieldName + "] field is not recognized");
                    }
                    break;
                case START_OBJECT:
                    if ("clear_caches".equals(fieldName)) {
                        BenchmarkSettings.ClearCachesSettings clearCachesSettings = new BenchmarkSettings.ClearCachesSettings();
                        builder.setClearCachesSettings(clearCachesSettings);
                        parseClearCaches(p, clearCachesSettings);
                    } else {
                        throw new ElasticsearchParseException("Failed parsing object field [" + fieldName + "] field is not recognized");
                    }
                    break;
                case FIELD_NAME:
                    fieldName = p.text();
                    break;
                case VALUE_NUMBER:
                    if ("num_executor_nodes".equals(fieldName)) {
                        builder.setNumExecutorNodes(p.intValue());
                    } else if ("iterations".equals(fieldName)) {
                        builder.setIterations(p.intValue());
                    } else if ("concurrency".equals(fieldName)) {
                        builder.setConcurrency(p.intValue());
                    } else if ("multiplier".equals(fieldName)) {
                        builder.setMultiplier(p.intValue());
                    } else if ("num_slowest".equals(fieldName)) {
                        builder.setNumSlowest(p.intValue());
                    } else {
                        throw new ElasticsearchParseException("Failed parsing numeric field [" + fieldName + "] field is not recognized");
                    }
                    break;
                case VALUE_BOOLEAN:
                    if ("warmup".equals(fieldName)) {
                        builder.setWarmup(p.booleanValue());
                    } else if ("clear_caches".equals(fieldName)) {
                        if (p.booleanValue()) {
                            throw new ElasticsearchParseException("Failed parsing field [" + fieldName + "] must specify which caches to clear");
                        } else {
                            builder.setAllowCacheClearing(false);
                        }
                    } else {
                        throw new ElasticsearchParseException("Failed parsing boolean field [" + fieldName + "] field is not recognized");
                    }
                    break;
                case VALUE_STRING:
                    if ("name".equals(fieldName)) {
                        builder.setBenchmarkId(p.text());
                    } else {
                        throw new ElasticsearchParseException("Failed parsing string field [" + fieldName + "] field is not recognized");
                    }
                    break;
                default:
                    throw new ElasticsearchParseException("Failed parsing " + token.name() + " field [" + fieldName + "] field is not recognized");
            }
        }

        return builder.request();
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.ElasticSearchParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.