org.elasticsearch.common.ParseField Java Examples

The following examples show how to use org.elasticsearch.common.ParseField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SQLPlugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public List<NamedXContentRegistry.Entry> getNamedXContent() {
    List<NamedXContentRegistry.Entry> entries = new ArrayList<>();
    entries.add(new NamedXContentRegistry.Entry(
        MetaData.Custom.class,
        new ParseField(UserDefinedFunctionsMetaData.TYPE),
        UserDefinedFunctionsMetaData::fromXContent
    ));
    entries.add(new NamedXContentRegistry.Entry(
        MetaData.Custom.class,
        new ParseField(ViewsMetaData.TYPE),
        ViewsMetaData::fromXContent
    ));

    if (userExtension != null) {
        entries.addAll(userExtension.getNamedXContent());
    }
    if (licenseExtension != null) {
        entries.addAll(licenseExtension.getNamedXContent());
    }
    return entries;
}
 
Example #2
Source File: ScriptParameterParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public ScriptParameterParser(Set<String> parameterNames) {
    ESLogger logger = Loggers.getLogger(getClass());
    deprecationLogger = new DeprecationLogger(logger);
    if (parameterNames == null || parameterNames.isEmpty()) {
        inlineParameters = Collections.singleton(ScriptService.SCRIPT_INLINE);
        fileParameters = Collections.singleton(ScriptService.SCRIPT_FILE);
        indexedParameters = Collections.singleton(ScriptService.SCRIPT_ID);
    } else {
        inlineParameters = new HashSet<>();
        fileParameters = new HashSet<>();
        indexedParameters = new HashSet<>();
        for (String parameterName : parameterNames) {
            if (ParseFieldMatcher.EMPTY.match(parameterName, ScriptService.SCRIPT_LANG)) {
                throw new IllegalArgumentException("lang is reserved and cannot be used as a parameter name");
            }
            inlineParameters.add(new ParseField(parameterName));
            fileParameters.add(new ParseField(parameterName + FILE_SUFFIX));
            indexedParameters.add(new ParseField(parameterName + INDEXED_SUFFIX));
        }
    }
}
 
Example #3
Source File: ConstructingObjectParser.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the consumer that does the "field just arrived" behavior. If the targetObject hasn't been built then it queues the value.
 * Otherwise it just applies the value just like {@linkplain ObjectParser} does.
 */
private <T> BiConsumer<Target, T> queueingConsumer(BiConsumer<Value, T> consumer, ParseField parseField) {
    return (target, v) -> {
        if (target.targetObject != null) {
            // The target has already been built. Just apply the consumer now.
            consumer.accept(target.targetObject, v);
            return;
        }
        /*
         * The target hasn't been built. Queue the consumer. The next two lines are the only allocations that ConstructingObjectParser
         * does during parsing other than the boxing the ObjectParser might do. The first one is to preserve a snapshot of the current
         * location so we can add it to the error message if parsing fails. The second one (the lambda) is the actual operation being
         * queued. Note that we don't do any of this if the target object has already been built.
         */
        XContentLocation location = target.parser.getTokenLocation();
        target.queue(targetObject -> {
            try {
                consumer.accept(targetObject, v);
            } catch (Exception e) {
                throw new XContentParseException(location,
                        "[" + objectParser.getName() + "] failed to parse field [" + parseField.getPreferredName() + "]", e);
            }
        });
    };
}
 
Example #4
Source File: ObjectParser.java    From crate with Apache License 2.0 5 votes vote down vote up
public void declareField(Parser<Value, Context> p, ParseField parseField, ValueType type) {
    if (parseField == null) {
        throw new IllegalArgumentException("[parseField] is required");
    }
    if (type == null) {
        throw new IllegalArgumentException("[type] is required");
    }
    FieldParser fieldParser = new FieldParser(p, type.supportedTokens(), parseField, type);
    for (String fieldValue : parseField.getAllNamesIncludedDeprecated()) {
        fieldParserMap.putIfAbsent(fieldValue, fieldParser);
    }
}
 
Example #5
Source File: PredictionAggregationParser.java    From elasticsearch-linear-regression with Apache License 2.0 5 votes vote down vote up
@Override
protected PredictionAggregationBuilder createInnerFactory(final String aggregationName,
    final Map<ParseField, Object> otherOptions) {
  final PredictionAggregationBuilder builder = new PredictionAggregationBuilder(aggregationName);
  if (otherOptions.containsKey(INPUTS)) {
    final List<Double> inputsList = (List<Double>) otherOptions.get(INPUTS);
    final double[] inputs = new double[inputsList.size()];
    int i = 0;
    for (final Double input : inputsList) {
      inputs[i++] = input;
    }
    builder.inputs(inputs);
  }
  return builder;
}
 
Example #6
Source File: LtrQueryParserPlugin.java    From elasticsearch-learning-to-rank with Apache License 2.0 5 votes vote down vote up
@Override
public List<NamedXContentRegistry.Entry> getNamedXContent() {
    return unmodifiableList(asList(
            new NamedXContentRegistry.Entry(StorableElement.class,
                    new ParseField(StoredFeature.TYPE),
                    (CheckedFunction<XContentParser, StorableElement, IOException>) StoredFeature::parse),
            new NamedXContentRegistry.Entry(StorableElement.class,
                    new ParseField(StoredFeatureSet.TYPE),
                    (CheckedFunction<XContentParser, StorableElement, IOException>) StoredFeatureSet::parse),
            new NamedXContentRegistry.Entry(StorableElement.class,
                    new ParseField(StoredLtrModel.TYPE),
                    (CheckedFunction<XContentParser, StorableElement, IOException>) StoredLtrModel::parse)
    ));
}
 
Example #7
Source File: ConstructingObjectParser.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void declareField(BiConsumer<Value, T> consumer, ContextParser<Context, T> parser, ParseField parseField, ValueType type) {
    if (consumer == null) {
        throw new IllegalArgumentException("[consumer] is required");
    }
    if (parser == null) {
        throw new IllegalArgumentException("[parser] is required");
    }
    if (parseField == null) {
        throw new IllegalArgumentException("[parseField] is required");
    }
    if (type == null) {
        throw new IllegalArgumentException("[type] is required");
    }

    if (consumer == REQUIRED_CONSTRUCTOR_ARG_MARKER || consumer == OPTIONAL_CONSTRUCTOR_ARG_MARKER) {
        /*
         * Constructor arguments are detected by these "marker" consumers. It keeps the API looking clean even if it is a bit sleezy. We
         * then build a new consumer directly against the object parser that triggers the "constructor arg just arrived behavior" of the
         * parser. Conveniently, we can close over the position of the constructor in the argument list so we don't need to do any fancy
         * or expensive lookups whenever the constructor args come in.
         */
        int position = constructorArgInfos.size();
        boolean required = consumer == REQUIRED_CONSTRUCTOR_ARG_MARKER;
        constructorArgInfos.add(new ConstructorArgInfo(parseField, required));
        objectParser.declareField((target, v) -> target.constructorArg(position, parseField, v), parser, parseField, type);
    } else {
        numberOfFields += 1;
        objectParser.declareField(queueingConsumer(consumer, parseField), parser, parseField, type);
    }
}
 
Example #8
Source File: ConstructingObjectParser.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void declareNamedObjects(BiConsumer<Value, List<T>> consumer, NamedObjectParser<T, Context> namedObjectParser,
        ParseField parseField) {
    if (consumer == null) {
        throw new IllegalArgumentException("[consumer] is required");
    }
    if (namedObjectParser == null) {
        throw new IllegalArgumentException("[parser] is required");
    }
    if (parseField == null) {
        throw new IllegalArgumentException("[parseField] is required");
    }

    if (consumer == REQUIRED_CONSTRUCTOR_ARG_MARKER || consumer == OPTIONAL_CONSTRUCTOR_ARG_MARKER) {
        /*
         * Constructor arguments are detected by this "marker" consumer. It
         * keeps the API looking clean even if it is a bit sleezy. We then
         * build a new consumer directly against the object parser that
         * triggers the "constructor arg just arrived behavior" of the
         * parser. Conveniently, we can close over the position of the
         * constructor in the argument list so we don't need to do any fancy
         * or expensive lookups whenever the constructor args come in.
         */
        int position = constructorArgInfos.size();
        boolean required = consumer == REQUIRED_CONSTRUCTOR_ARG_MARKER;
        constructorArgInfos.add(new ConstructorArgInfo(parseField, required));
        objectParser.declareNamedObjects((target, v) -> target.constructorArg(position, parseField, v), namedObjectParser, parseField);
    } else {
        numberOfFields += 1;
        objectParser.declareNamedObjects(queueingConsumer(consumer, parseField), namedObjectParser, parseField);
    }
}
 
Example #9
Source File: ConstructingObjectParser.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void declareNamedObjects(BiConsumer<Value, List<T>> consumer, NamedObjectParser<T, Context> namedObjectParser,
        Consumer<Value> orderedModeCallback, ParseField parseField) {
    if (consumer == null) {
        throw new IllegalArgumentException("[consumer] is required");
    }
    if (namedObjectParser == null) {
        throw new IllegalArgumentException("[parser] is required");
    }
    if (orderedModeCallback == null) {
        throw new IllegalArgumentException("[orderedModeCallback] is required");
    }
    if (parseField == null) {
        throw new IllegalArgumentException("[parseField] is required");
    }

    if (consumer == REQUIRED_CONSTRUCTOR_ARG_MARKER || consumer == OPTIONAL_CONSTRUCTOR_ARG_MARKER) {
        /*
         * Constructor arguments are detected by this "marker" consumer. It
         * keeps the API looking clean even if it is a bit sleezy. We then
         * build a new consumer directly against the object parser that
         * triggers the "constructor arg just arrived behavior" of the
         * parser. Conveniently, we can close over the position of the
         * constructor in the argument list so we don't need to do any fancy
         * or expensive lookups whenever the constructor args come in.
         */
        int position = constructorArgInfos.size();
        boolean required = consumer == REQUIRED_CONSTRUCTOR_ARG_MARKER;
        constructorArgInfos.add(new ConstructorArgInfo(parseField, required));
        objectParser.declareNamedObjects((target, v) -> target.constructorArg(position, parseField, v), namedObjectParser,
                wrapOrderedModeCallBack(orderedModeCallback), parseField);
    } else {
        numberOfFields += 1;
        objectParser.declareNamedObjects(queueingConsumer(consumer, parseField), namedObjectParser,
                wrapOrderedModeCallBack(orderedModeCallback), parseField);
    }
}
 
Example #10
Source File: ConstructingObjectParser.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Set a constructor argument and build the target object if all constructor arguments have arrived.
 */
private void constructorArg(int position, ParseField parseField, Object value) {
    if (constructorArgs[position] != null) {
        throw new IllegalArgumentException("Can't repeat param [" + parseField + "]");
    }
    constructorArgs[position] = value;
    constructorArgsCollected++;
    if (constructorArgsCollected == constructorArgInfos.size()) {
        buildTarget();
    }
}
 
Example #11
Source File: AbstractObjectParser.java    From crate with Apache License 2.0 5 votes vote down vote up
public <T> void declareField(BiConsumer<Value, T> consumer, CheckedFunction<XContentParser, T, IOException> parser,
        ParseField parseField, ValueType type) {
    if (parser == null) {
        throw new IllegalArgumentException("[parser] is required");
    }
    declareField(consumer, (p, c) -> parser.apply(p), parseField, type);
}
 
Example #12
Source File: ObjectParser.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void declareField(BiConsumer<Value, T> consumer, ContextParser<Context, T> parser, ParseField parseField,
        ValueType type) {
    if (consumer == null) {
        throw new IllegalArgumentException("[consumer] is required");
    }
    if (parser == null) {
        throw new IllegalArgumentException("[parser] is required");
    }
    declareField((p, v, c) -> consumer.accept(v, parser.parse(p, c)), parseField, type);
}
 
Example #13
Source File: ObjectParser.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void declareNamedObjects(BiConsumer<Value, List<T>> consumer, NamedObjectParser<T, Context> namedObjectParser,
        ParseField field) {
    Consumer<Value> orderedModeCallback = (v) -> {
        throw new IllegalArgumentException("[" + field + "] doesn't support arrays. Use a single object with multiple fields.");
    };
    declareNamedObjects(consumer, namedObjectParser, orderedModeCallback, field);
}
 
Example #14
Source File: ClusterModule.java    From crate with Apache License 2.0 5 votes vote down vote up
public static List<NamedXContentRegistry.Entry> getNamedXWriteables() {
    List<NamedXContentRegistry.Entry> entries = new ArrayList<>();
    // Metadata
    entries.add(new NamedXContentRegistry.Entry(MetaData.Custom.class, new ParseField(RepositoriesMetaData.TYPE),
        RepositoriesMetaData::fromXContent));
    entries.add(new NamedXContentRegistry.Entry(MetaData.Custom.class, new ParseField(IndexGraveyard.TYPE),
        IndexGraveyard::fromXContent));
    return entries;
}
 
Example #15
Source File: AbstractAllocateAllocationCommand.java    From crate with Apache License 2.0 5 votes vote down vote up
protected static <T extends Builder<?>> ObjectParser<T, Void> createAllocateParser(String command) {
    ObjectParser<T, Void> parser = new ObjectParser<>(command);
    parser.declareString(Builder::setIndex, new ParseField(INDEX_FIELD));
    parser.declareInt(Builder::setShard, new ParseField(SHARD_FIELD));
    parser.declareString(Builder::setNode, new ParseField(NODE_FIELD));
    return parser;
}
 
Example #16
Source File: EnterpriseUsersExtension.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public List<NamedXContentRegistry.Entry> getNamedXContent() {
    List<NamedXContentRegistry.Entry> entries = new ArrayList<>(2);
    entries.add(new NamedXContentRegistry.Entry(
        MetaData.Custom.class,
        new ParseField(UsersMetaData.TYPE),
        UsersMetaData::fromXContent
    ));
    entries.add(new NamedXContentRegistry.Entry(
        MetaData.Custom.class,
        new ParseField(UsersPrivilegesMetaData.TYPE),
        UsersPrivilegesMetaData::fromXContent
    ));
    return entries;
}
 
Example #17
Source File: EnterpriseLicenseExtension.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public List<NamedXContentRegistry.Entry> getNamedXContent() {
    return Collections.singletonList(new NamedXContentRegistry.Entry(
        MetaData.Custom.class,
        new ParseField(LicenseKey.WRITEABLE_TYPE),
        LicenseKey::fromXContent
    ));
}
 
Example #18
Source File: BaseParser.java    From elasticsearch-linear-regression with Apache License 2.0 5 votes vote down vote up
@Override
protected B createFactory(final String aggregationName,
    final ValuesSourceType valuesSourceType,
    final ValueType targetValueType, final Map<ParseField, Object> otherOptions) {
  final B builder = createInnerFactory(aggregationName, otherOptions);
  final String mode = (String) otherOptions.get(MULTIVALUE_MODE_FIELD);
  if (mode != null) {
    builder.multiValueMode(MultiValueMode.fromString(mode));
  }
  return builder;
}
 
Example #19
Source File: BucketHelpers.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private GapPolicy(byte id, String name) {
    this.id = id;
    this.parseField = new ParseField(name);
}
 
Example #20
Source File: BaseParser.java    From elasticsearch-linear-regression with Apache License 2.0 4 votes vote down vote up
protected abstract B createInnerFactory(String aggregationName,
Map<ParseField, Object> otherOptions);
 
Example #21
Source File: AbstractObjectParser.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Declares a field that can contain an array of elements listed in the type ValueType enum
 */
public <T> void declareFieldArray(BiConsumer<Value, List<T>> consumer, ContextParser<Context, T> itemParser,
                                  ParseField field, ValueType type) {
    declareField(consumer, (p, c) -> parseArray(p, () -> itemParser.parse(p, c)), field, type);
}
 
Example #22
Source File: SamplerAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
ExecutionMode(ParseField parseField) {
    this.parseField = parseField;
}
 
Example #23
Source File: TermsAggregatorFactory.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
ExecutionMode(ParseField parseField) {
    this.parseField = parseField;
}
 
Example #24
Source File: SignificantTermsAggregatorFactory.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
ExecutionMode(ParseField parseField) {
    this.parseField = parseField;
}
 
Example #25
Source File: GeoPointParser.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public GeoPointParser(String aggName, InternalAggregation.Type aggType, SearchContext context, ParseField field) {
    this.aggName = aggName;
    this.aggType = aggType;
    this.context = context;
    this.field = field;
}
 
Example #26
Source File: Aggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public ParseField parseField() {
    return parseField;
}
 
Example #27
Source File: ConstructingObjectParser.java    From crate with Apache License 2.0 4 votes vote down vote up
ConstructorArgInfo(ParseField field, boolean required) {
    this.field = field;
    this.required = required;
}
 
Example #28
Source File: Aggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
SubAggCollectionMode(ParseField parseField) {
    this.parseField = parseField;
}
 
Example #29
Source File: AbstractObjectParser.java    From crate with Apache License 2.0 4 votes vote down vote up
public void declareStringArray(BiConsumer<Value, List<String>> consumer, ParseField field) {
    declareFieldArray(consumer, (p, c) -> p.text(), field, ValueType.STRING_ARRAY);
}
 
Example #30
Source File: HoltWintersModel.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
SeasonalityType(byte id, String name) {
    this.id = id;
    this.parseField = new ParseField(name);
}