Search in sources :

Example 1 with ObjectParser

use of org.elasticsearch.common.xcontent.ObjectParser in project elasticsearch by elastic.

the class AbstractAllocateAllocationCommand method createAllocateParser.

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;
}
Also used : ObjectParser(org.elasticsearch.common.xcontent.ObjectParser) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ParseField(org.elasticsearch.common.ParseField)

Example 2 with ObjectParser

use of org.elasticsearch.common.xcontent.ObjectParser in project elasticsearch by elastic.

the class SearchHit method declareMetaDataFields.

/**
     * we need to declare parse fields for each metadata field, except for _ID, _INDEX and _TYPE which are
     * handled individually. All other fields are parsed to an entry in the fields map
     */
private static void declareMetaDataFields(ObjectParser<Map<String, Object>, Void> parser) {
    for (String metadatafield : MapperService.getAllMetaFields()) {
        if (metadatafield.equals(Fields._ID) == false && metadatafield.equals(Fields._INDEX) == false && metadatafield.equals(Fields._TYPE) == false) {
            parser.declareField((map, field) -> {
                @SuppressWarnings("unchecked") Map<String, SearchHitField> fieldMap = (Map<String, SearchHitField>) map.computeIfAbsent(Fields.FIELDS, v -> new HashMap<String, SearchHitField>());
                fieldMap.put(field.getName(), field);
            }, (p, c) -> {
                List<Object> values = new ArrayList<>();
                values.add(parseStoredFieldsValue(p));
                return new SearchHitField(metadatafield, values);
            }, new ParseField(metadatafield), ValueType.VALUE);
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) Arrays(java.util.Arrays) ConstructingObjectParser.constructorArg(org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg) Nullable(org.elasticsearch.common.Nullable) ParsingException(org.elasticsearch.common.ParsingException) XContentParserUtils.throwUnknownField(org.elasticsearch.common.xcontent.XContentParserUtils.throwUnknownField) Streamable(org.elasticsearch.common.io.stream.Streamable) HashMap(java.util.HashMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParserUtils.ensureExpectedToken(org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken) Strings(org.elasticsearch.common.Strings) ArrayList(java.util.ArrayList) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) Text(org.elasticsearch.common.text.Text) Map(java.util.Map) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField) ConstructingObjectParser.optionalConstructorArg(org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg) Collections.singletonMap(java.util.Collections.singletonMap) ParseField(org.elasticsearch.common.ParseField) Lucene.readExplanation(org.elasticsearch.common.lucene.Lucene.readExplanation) XContentParserUtils.parseStoredFieldsValue(org.elasticsearch.common.xcontent.XContentParserUtils.parseStoredFieldsValue) CompletionSuggestion(org.elasticsearch.search.suggest.completion.CompletionSuggestion) Collections.emptyMap(java.util.Collections.emptyMap) Explanation(org.apache.lucene.search.Explanation) Iterator(java.util.Iterator) ToXContent(org.elasticsearch.common.xcontent.ToXContent) IOException(java.io.IOException) BytesReference(org.elasticsearch.common.bytes.BytesReference) CompressorFactory(org.elasticsearch.common.compress.CompressorFactory) XContentParser(org.elasticsearch.common.xcontent.XContentParser) SourceLookup(org.elasticsearch.search.lookup.SourceLookup) Objects(java.util.Objects) MapperService(org.elasticsearch.index.mapper.MapperService) SourceFieldMapper(org.elasticsearch.index.mapper.SourceFieldMapper) List(java.util.List) HighlightField.readHighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField.readHighlightField) Lucene.writeExplanation(org.elasticsearch.common.lucene.Lucene.writeExplanation) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ValueType(org.elasticsearch.common.xcontent.ObjectParser.ValueType) ObjectParser(org.elasticsearch.common.xcontent.ObjectParser) ToXContentObject(org.elasticsearch.common.xcontent.ToXContentObject) ConstructingObjectParser(org.elasticsearch.common.xcontent.ConstructingObjectParser) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) Writeable(org.elasticsearch.common.io.stream.Writeable) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ToXContentObject(org.elasticsearch.common.xcontent.ToXContentObject) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) ParseField(org.elasticsearch.common.ParseField)

Example 3 with ObjectParser

use of org.elasticsearch.common.xcontent.ObjectParser in project elasticsearch by elastic.

the class SignificantTermsAggregationBuilder method getParser.

public static Aggregator.Parser getParser(ParseFieldRegistry<SignificanceHeuristicParser> significanceHeuristicParserRegistry) {
    ObjectParser<SignificantTermsAggregationBuilder, QueryParseContext> parser = new ObjectParser<>(SignificantTermsAggregationBuilder.NAME);
    ValuesSourceParserHelper.declareAnyFields(parser, true, true);
    parser.declareInt(SignificantTermsAggregationBuilder::shardSize, TermsAggregationBuilder.SHARD_SIZE_FIELD_NAME);
    parser.declareLong(SignificantTermsAggregationBuilder::minDocCount, TermsAggregationBuilder.MIN_DOC_COUNT_FIELD_NAME);
    parser.declareLong(SignificantTermsAggregationBuilder::shardMinDocCount, TermsAggregationBuilder.SHARD_MIN_DOC_COUNT_FIELD_NAME);
    parser.declareInt(SignificantTermsAggregationBuilder::size, TermsAggregationBuilder.REQUIRED_SIZE_FIELD_NAME);
    parser.declareString(SignificantTermsAggregationBuilder::executionHint, TermsAggregationBuilder.EXECUTION_HINT_FIELD_NAME);
    parser.declareObject(SignificantTermsAggregationBuilder::backgroundFilter, (p, context) -> context.parseInnerQueryBuilder(), SignificantTermsAggregationBuilder.BACKGROUND_FILTER);
    parser.declareField((b, v) -> b.includeExclude(IncludeExclude.merge(v, b.includeExclude())), IncludeExclude::parseInclude, IncludeExclude.INCLUDE_FIELD, ObjectParser.ValueType.OBJECT_ARRAY_OR_STRING);
    parser.declareField((b, v) -> b.includeExclude(IncludeExclude.merge(b.includeExclude(), v)), IncludeExclude::parseExclude, IncludeExclude.EXCLUDE_FIELD, ObjectParser.ValueType.STRING_ARRAY);
    for (String name : significanceHeuristicParserRegistry.getNames()) {
        parser.declareObject(SignificantTermsAggregationBuilder::significanceHeuristic, (p, context) -> {
            SignificanceHeuristicParser significanceHeuristicParser = significanceHeuristicParserRegistry.lookupReturningNullIfNotFound(name);
            return significanceHeuristicParser.parse(context);
        }, new ParseField(name));
    }
    return new Aggregator.Parser() {

        @Override
        public AggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
            return parser.parse(context.parser(), new SignificantTermsAggregationBuilder(aggregationName, null), context);
        }
    };
}
Also used : ObjectParser(org.elasticsearch.common.xcontent.ObjectParser) QueryParseContext(org.elasticsearch.index.query.QueryParseContext) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude) SignificanceHeuristicParser(org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser) ParseField(org.elasticsearch.common.ParseField) SignificanceHeuristicParser(org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser) ObjectParser(org.elasticsearch.common.xcontent.ObjectParser)

Example 4 with ObjectParser

use of org.elasticsearch.common.xcontent.ObjectParser in project crate by crate.

the class AbstractAllocateAllocationCommand method createAllocateParser.

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;
}
Also used : ObjectParser(org.elasticsearch.common.xcontent.ObjectParser) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ParseField(org.elasticsearch.common.ParseField)

Aggregations

ParseField (org.elasticsearch.common.ParseField)4 ObjectParser (org.elasticsearch.common.xcontent.ObjectParser)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Explanation (org.apache.lucene.search.Explanation)1 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)1 Nullable (org.elasticsearch.common.Nullable)1 ParsingException (org.elasticsearch.common.ParsingException)1 Strings (org.elasticsearch.common.Strings)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1