Package org.elasticsearch.search

Examples of org.elasticsearch.search.SearchParseException


                if (PARAMS_FIELD.match(currentFieldName)) {
                    params = parser.map();
                } else if (REDUCE_PARAMS_FIELD.match(currentFieldName)) {
                  reduceParams = parser.map();
                } else {
                    throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
                }
            } else if (token.isValue()) {
                if (!scriptParameterParser.token(currentFieldName, token, parser)) {
                    throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
                }
            } else {
                throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].");
            }
        }
       
        ScriptParameterValue initScriptValue = scriptParameterParser.getScriptParameterValue(INIT_SCRIPT);
        String initScript = null;
        ScriptType initScriptType = null;
        if (initScriptValue != null) {
            initScript = initScriptValue.script();
            initScriptType = initScriptValue.scriptType();
        }
        ScriptParameterValue mapScriptValue = scriptParameterParser.getScriptParameterValue(MAP_SCRIPT);
        String mapScript = null;
        ScriptType mapScriptType = null;
        if (mapScriptValue != null) {
            mapScript = mapScriptValue.script();
            mapScriptType = mapScriptValue.scriptType();
        }
        ScriptParameterValue combineScriptValue = scriptParameterParser.getScriptParameterValue(COMBINE_SCRIPT);
        String combineScript = null;
        ScriptType combineScriptType = null;
        if (combineScriptValue != null) {
            combineScript = combineScriptValue.script();
            combineScriptType = combineScriptValue.scriptType();
        }
        ScriptParameterValue reduceScriptValue = scriptParameterParser.getScriptParameterValue(REDUCE_SCRIPT);
        String reduceScript = null;
        ScriptType reduceScriptType = null;
        if (reduceScriptValue != null) {
            reduceScript = reduceScriptValue.script();
            reduceScriptType = reduceScriptValue.scriptType();
        }
        scriptLang = scriptParameterParser.lang();
       
        if (mapScript == null) {
            throw new SearchParseException(context, "map_script field is required in [" + aggregationName + "].");
        }
        return new ScriptedMetricAggregator.Factory(aggregationName, scriptLang, initScriptType, initScript, mapScriptType, mapScript,
                combineScriptType, combineScript, reduceScriptType, reduceScript, params, reduceParams);
    }
View Full Code Here


                if ("rehash".equals(currentFieldName)) {
                    rehash = parser.booleanValue();
                } else if (PRECISION_THRESHOLD.match(currentFieldName)) {
                    precisionThreshold = parser.longValue();
                } else {
                    throw new SearchParseException(context, "Unknown key for a " + token + " in [" + name + "]: [" + currentFieldName + "].");
                }
            } else {
                throw new SearchParseException(context, "Unexpected token " + token + " in [" + name + "].");
            }
        }

        ValuesSourceConfig<?> config = vsParser.config();
View Full Code Here

                if (Double.isNaN(lon)) {
                    lon = parser.doubleValue();
                } else if (Double.isNaN(lat)) {
                    lat = parser.doubleValue();
                } else {
                    throw new SearchParseException(context, "malformed [" + currentFieldName + "] geo point array in [" +
                            aggName + "] " + aggType + " aggregation. a geo point array must be of the form [lon, lat]");
                }
            }
            point = new GeoPoint(lat, lon);
            return true;
        }
        if (token == XContentParser.Token.START_OBJECT) {
            double lat = Double.NaN;
            double lon = Double.NaN;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else if (token == XContentParser.Token.VALUE_NUMBER) {
                    if ("lat".equals(currentFieldName)) {
                        lat = parser.doubleValue();
                    } else if ("lon".equals(currentFieldName)) {
                        lon = parser.doubleValue();
                    }
                }
            }
            if (Double.isNaN(lat) || Double.isNaN(lon)) {
                throw new SearchParseException(context, "malformed [" + currentFieldName + "] geo point object. either [lat] or [lon] (or both) are " +
                        "missing in [" + aggName + "] " + aggType + " aggregation");
            }
            point = new GeoPoint(lat, lon);
            return true;
        }
View Full Code Here

                input.format = parser.text();
            } else if (scriptable) {
                if ("value_type".equals(currentFieldName) || "valueType".equals(currentFieldName)) {
                    input.valueType = ValueType.resolveForScript(parser.text());
                    if (targetValueType != null && input.valueType.isNotA(targetValueType)) {
                        throw new SearchParseException(context, aggType.name() + " aggregation [" + aggName +
                                "] was configured with an incompatible value type [" + input.valueType + "]. [" + aggType +
                                "] aggregation can only work on value of type [" + targetValueType + "]");
                    }
                } else if (!scriptParameterParser.token(currentFieldName, token, parser)) {
                    return false;
View Full Code Here

        AggregatorFactories.Builder factories = new AggregatorFactories.Builder();

        XContentParser.Token token = null;
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token != XContentParser.Token.FIELD_NAME) {
                throw new SearchParseException(context, "Unexpected token " + token + " in [aggs]: aggregations definitions must start with the name of the aggregation.");
            }
            final String aggregationName = parser.currentName();
            if (!validAggMatcher.reset(aggregationName).matches()) {
                throw new SearchParseException(context, "Invalid aggregation name [" + aggregationName + "]. Aggregation names must be alpha-numeric and can only contain '_' and '-'");
            }

            token = parser.nextToken();
            if (token != XContentParser.Token.START_OBJECT) {
                throw new SearchParseException(context, "Aggregation definition for [" + aggregationName + " starts with a [" + token + "], expected a [" + XContentParser.Token.START_OBJECT + "].");
            }

            AggregatorFactory factory = null;
            AggregatorFactories subFactories = null;

            Map<String, Object> metaData = null;

            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token != XContentParser.Token.FIELD_NAME) {
                    throw new SearchParseException(context, "Expected [" + XContentParser.Token.FIELD_NAME + "] under a [" + XContentParser.Token.START_OBJECT + "], but got a [" + token + "] in [" + aggregationName + "]");
                }
                final String fieldName = parser.currentName();

                token = parser.nextToken();
                if (token != XContentParser.Token.START_OBJECT) {
                    throw new SearchParseException(context, "Expected [" + XContentParser.Token.START_OBJECT + "] under [" + fieldName + "], but got a [" + token + "] in [" + aggregationName + "]");
                }

                switch (fieldName) {
                    case "meta":
                        metaData = parser.map();
                        break;
                    case "aggregations":
                    case "aggs":
                        if (subFactories != null) {
                            throw new SearchParseException(context, "Found two sub aggregation definitions under [" + aggregationName + "]");
                        }
                        subFactories = parseAggregators(parser, context, level+1);
                        break;
                    default:
                        if (factory != null) {
                            throw new SearchParseException(context, "Found two aggregation type definitions in [" + aggregationName + "]: [" + factory.type + "] and [" + fieldName + "]");
                        }
                        Aggregator.Parser aggregatorParser = parser(fieldName);
                        if (aggregatorParser == null) {
                            throw new SearchParseException(context, "Could not find aggregator type [" + fieldName + "] in [" + aggregationName + "]");
                        }
                        factory = aggregatorParser.parse(aggregationName, parser, context);
                }
            }

            if (factory == null) {
                throw new SearchParseException(context, "Missing definition for aggregation [" + aggregationName + "]");
            }

            if (metaData != null) {
                factory.setMetaData(metaData);
            }
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.SearchParseException

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.