Package org.elasticsearch

Examples of org.elasticsearch.ElasticsearchParseException


                    } else if ("from_node".equals(currentFieldName) || "fromNode".equals(currentFieldName)) {
                        fromNode = parser.text();
                    } else if ("to_node".equals(currentFieldName) || "toNode".equals(currentFieldName)) {
                        toNode = parser.text();
                    } else {
                        throw new ElasticsearchParseException("[move] command does not support field [" + currentFieldName + "]");
                    }
                } else {
                    throw new ElasticsearchParseException("[move] command does not support complex json tokens [" + token + "]");
                }
            }
            if (index == null) {
                throw new ElasticsearchParseException("[move] command missing the index parameter");
            }
            if (shardId == -1) {
                throw new ElasticsearchParseException("[move] command missing the shard parameter");
            }
            if (fromNode == null) {
                throw new ElasticsearchParseException("[move] command missing the from_node parameter");
            }
            if (toNode == null) {
                throw new ElasticsearchParseException("[move] command missing the to_node parameter");
            }
            return new MoveAllocationCommand(new ShardId(index, shardId), fromNode, toNode);
        }
View Full Code Here


            }
            return mappings;
        } else if (configuration == null) {
            return ContextMapping.EMPTY_MAPPING;
        } else {
            throw new ElasticsearchParseException("no valid context configuration");
        }
    }
View Full Code Here

    protected static ContextMapping loadMapping(String name, Map<String, Object> config) throws ElasticsearchParseException {
        final Object argType = config.get(ContextMapping.FIELD_TYPE);
       
        if (argType == null) {
            throw new ElasticsearchParseException("missing [" + ContextMapping.FIELD_TYPE + "] in context mapping");
        }

        final String type = argType.toString();

        if (GeolocationContextMapping.TYPE.equals(type)) {
            return GeolocationContextMapping.load(name, config);
        } else if (CategoryContextMapping.TYPE.equals(type)) {
            return CategoryContextMapping.load(name, config);
        } else {
            throw new ElasticsearchParseException("unknown context type[" + type + "]");
        }
    }
View Full Code Here

                if (QueryRescorer.NAME.equals(fieldName)) {
                    // we only have one at this point
                    Rescorer rescorer = QueryRescorer.INSTANCE;
                    token = parser.nextToken();
                    if (token != XContentParser.Token.START_OBJECT) {
                        throw new ElasticsearchParseException("rescore type malformed, must start with start_object");
                    }
                    rescoreContext = rescorer.parse(parser, context);
                }
            } else if (token.isValue()) {
                if ("window_size".equals(fieldName)) {
View Full Code Here

    public static AllocationCommands fromXContent(XContentParser parser) throws IOException {
        AllocationCommands commands = new AllocationCommands();

        XContentParser.Token token = parser.currentToken();
        if (token == null) {
            throw new ElasticsearchParseException("No commands");
        }
        if (token == XContentParser.Token.FIELD_NAME) {
            if (!parser.currentName().equals("commands")) {
                throw new ElasticsearchParseException("expected field name to be named `commands`, got " + parser.currentName());
            }
            if (!parser.currentName().equals("commands")) {
                throw new ElasticsearchParseException("expected field name to be named `commands`, got " + parser.currentName());
            }
            token = parser.nextToken();
            if (token != XContentParser.Token.START_ARRAY) {
                throw new ElasticsearchParseException("commands should follow with an array element");
            }
        } else if (token == XContentParser.Token.START_ARRAY) {
            // ok...
        } else {
            throw new ElasticsearchParseException("expected either field name commands, or start array, got " + 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(AllocationCommands.lookupFactorySafe(commandName).fromXContent(parser));
                // move to the end object one
                if (parser.nextToken() != XContentParser.Token.END_OBJECT) {
                    throw new ElasticsearchParseException("allocation command is malformed, done parsing a command, but didn't get END_OBJECT, got " + token);
                }
            } else {
                throw new ElasticsearchParseException("allocation command is malformed, got token " + token);
            }
        }
        return commands;
    }
View Full Code Here

            if(token == Token.START_OBJECT) {
                while ((token = parser.nextToken()) != Token.END_OBJECT) {
                    String name = parser.text();
                    ContextMapping mapping = mappings.get(name);
                    if (mapping == null) {
                        throw new ElasticsearchParseException("no mapping defined for [" + name + "]");
                    }
                    parser.nextToken();
                    querySet.put(name, mapping.parseQuery(name, parser));
                }
            }
View Full Code Here

                // 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" + parser.currentToken());
                }
                double lat = parser.doubleValue();
                GeoPoint point = new GeoPoint();
                point.reset(lat, lon);
                geoPoints.add(point);
View Full Code Here

            ArrayList<String> values = Lists.newArrayList();
            while((token = parser.nextToken()) != Token.END_ARRAY) {
                values.add(parser.text());
            }
            if(values.isEmpty()) {
                throw new ElasticsearchParseException("FieldConfig must contain a least one category");
            }
            return new FieldConfig(fieldName, null, values);
        } else {
            throw new ElasticsearchParseException("FieldConfig must be either [null], a string or a list of strings");
        }
    }
View Full Code Here

     * @return new {@link GeolocationContextMapping} configured by the parameters of
     *         <code>config</code>
     */
    protected static GeolocationContextMapping load(String name, Map<String, Object> config) {
        if (!config.containsKey(FIELD_PRECISION)) {
            throw new ElasticsearchParseException("field [precision] is missing");
        }

        final GeolocationContextMapping.Builder builder = new GeolocationContextMapping.Builder(name);

        if (config != null) {
            final Object configPrecision = config.get(FIELD_PRECISION);
            if (configPrecision == null) {
                // ignore precision
            } else if (configPrecision instanceof Integer) {
                builder.precision((Integer) configPrecision);
            } else if (configPrecision instanceof Long) {
                builder.precision((Long) configPrecision);
            } else if (configPrecision instanceof Double) {
                builder.precision((Double) configPrecision);
            } else if (configPrecision instanceof Float) {
                builder.precision((Float) configPrecision);
            } else if (configPrecision instanceof Iterable) {
                for (Object precision : (Iterable)configPrecision) {
                    if (precision instanceof Integer) {
                        builder.precision((Integer) precision);
                    } else if (precision instanceof Long) {
                        builder.precision((Long) precision);
                    } else if (precision instanceof Double) {
                        builder.precision((Double) precision);
                    } else if (precision instanceof Float) {
                        builder.precision((Float) precision);
                    } else {
                        builder.precision(precision.toString());
                    }
                }
            } else {
                builder.precision(configPrecision.toString());
            }

            final Object configNeighbors = config.get(FIELD_NEIGHBORS);
            if (configNeighbors != null) {
                builder.neighbors((Boolean) configNeighbors);
            }

            final Object def = config.get(FIELD_MISSING);
            if (def != null) {
                if (def instanceof Iterable) {
                    for (Object location : (Iterable)def) {
                        builder.addDefaultLocation(location.toString());   
                    }
                } else if (def instanceof String) {
                    builder.addDefaultLocation(def.toString());
                } else if (def instanceof Map) {
                    Map<String, Object> latlonMap = (Map<String, Object>) def;
                    if (!latlonMap.containsKey("lat") || !(latlonMap.get("lat") instanceof Double)) {
                        throw new ElasticsearchParseException("field [" + FIELD_MISSING + "] map must have field lat and a valid latitude");
                    }
                    if (!latlonMap.containsKey("lon") || !(latlonMap.get("lon") instanceof Double)) {
                        throw new ElasticsearchParseException("field [" + FIELD_MISSING + "] map must have field lon and a valid longitude");
                    }
                    builder.addDefaultLocation(Double.valueOf(latlonMap.get("lat").toString()), Double.valueOf(latlonMap.get("lon").toString()));
                } else {
                    throw new ElasticsearchParseException("field [" + FIELD_MISSING + "] must be of type string or list");
                }
            }

            final Object fieldName = config.get(FIELD_FIELDNAME);
            if (fieldName != null) {
View Full Code Here

                if(parser.nextToken() == Token.VALUE_NUMBER) {
                    double lat = parser.doubleValue();
                    if(parser.nextToken() == Token.END_ARRAY) {
                        return Collections.singleton(GeoHashUtils.encode(lat, lon));
                    } else {
                        throw new ElasticsearchParseException("only two values expected");
                    }
                } else {
                    throw new ElasticsearchParseException("latitue must be a numeric value");
                }
            } else {
                // otherwise it's a list of locations
                ArrayList<String> result = Lists.newArrayList();
                while (token != Token.END_ARRAY) {
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.