Search in sources :

Example 6 with ParseField

use of org.opensearch.common.ParseField in project OpenSearch by opensearch-project.

the class JsonLogLine method createParser.

private static ObjectParser<JsonLogLine, Void> createParser(boolean ignoreUnknownFields) {
    ObjectParser<JsonLogLine, Void> parser = new ObjectParser<>("search_template", ignoreUnknownFields, JsonLogLine::new);
    parser.declareString(JsonLogLine::setType, new ParseField("type"));
    parser.declareString(JsonLogLine::setTimestamp, new ParseField("timestamp"));
    parser.declareString(JsonLogLine::setLevel, new ParseField("level"));
    parser.declareString(JsonLogLine::setComponent, new ParseField("component"));
    parser.declareString(JsonLogLine::setClusterName, new ParseField("cluster.name"));
    parser.declareString(JsonLogLine::setNodeName, new ParseField("node.name"));
    parser.declareString(JsonLogLine::setClusterUuid, new ParseField("cluster.uuid"));
    parser.declareString(JsonLogLine::setNodeId, new ParseField("node.id"));
    parser.declareString(JsonLogLine::setMessage, new ParseField("message"));
    parser.declareStringArray(JsonLogLine::setStacktrace, new ParseField("stacktrace"));
    return parser;
}
Also used : ObjectParser(org.opensearch.common.xcontent.ObjectParser) ParseField(org.opensearch.common.ParseField)

Example 7 with ParseField

use of org.opensearch.common.ParseField in project OpenSearch by opensearch-project.

the class ParsedSignificantTerms method declareParsedSignificantTermsFields.

static void declareParsedSignificantTermsFields(final ObjectParser<? extends ParsedSignificantTerms, Void> objectParser, final CheckedFunction<XContentParser, ParsedSignificantTerms.ParsedBucket, IOException> bucketParser) {
    declareMultiBucketAggregationFields(objectParser, bucketParser::apply, bucketParser::apply);
    objectParser.declareLong((parsedTerms, value) -> parsedTerms.subsetSize = value, CommonFields.DOC_COUNT);
    objectParser.declareLong((parsedTerms, value) -> parsedTerms.supersetSize = value, new ParseField(InternalMappedSignificantTerms.BG_COUNT));
}
Also used : ParseField(org.opensearch.common.ParseField)

Example 8 with ParseField

use of org.opensearch.common.ParseField in project OpenSearch by opensearch-project.

the class SearchHit method declareInnerHitsParseFields.

public static void declareInnerHitsParseFields(ObjectParser<Map<String, Object>, Void> parser) {
    parser.declareString((map, value) -> map.put(Fields._INDEX, value), new ParseField(Fields._INDEX));
    parser.declareString((map, value) -> map.put(Fields._ID, value), new ParseField(Fields._ID));
    parser.declareString((map, value) -> map.put(Fields._NODE, value), new ParseField(Fields._NODE));
    parser.declareField((map, value) -> map.put(Fields._SCORE, value), SearchHit::parseScore, new ParseField(Fields._SCORE), ValueType.FLOAT_OR_NULL);
    parser.declareLong((map, value) -> map.put(Fields._VERSION, value), new ParseField(Fields._VERSION));
    parser.declareLong((map, value) -> map.put(Fields._SEQ_NO, value), new ParseField(Fields._SEQ_NO));
    parser.declareLong((map, value) -> map.put(Fields._PRIMARY_TERM, value), new ParseField(Fields._PRIMARY_TERM));
    parser.declareField((map, value) -> map.put(Fields._SHARD, value), (p, c) -> ShardId.fromString(p.text()), new ParseField(Fields._SHARD), ValueType.STRING);
    parser.declareObject((map, value) -> map.put(SourceFieldMapper.NAME, value), (p, c) -> parseSourceBytes(p), new ParseField(SourceFieldMapper.NAME));
    parser.declareObject((map, value) -> map.put(Fields.HIGHLIGHT, value), (p, c) -> parseHighlightFields(p), new ParseField(Fields.HIGHLIGHT));
    parser.declareObject((map, value) -> {
        Map<String, DocumentField> fieldMap = get(Fields.FIELDS, map, new HashMap<String, DocumentField>());
        fieldMap.putAll(value);
        map.put(DOCUMENT_FIELDS, fieldMap);
    }, (p, c) -> parseFields(p), new ParseField(Fields.FIELDS));
    parser.declareObject((map, value) -> map.put(Fields._EXPLANATION, value), (p, c) -> parseExplanation(p), new ParseField(Fields._EXPLANATION));
    parser.declareObject((map, value) -> map.put(NestedIdentity._NESTED, value), NestedIdentity::fromXContent, new ParseField(NestedIdentity._NESTED));
    parser.declareObject((map, value) -> map.put(Fields.INNER_HITS, value), (p, c) -> parseInnerHits(p), new ParseField(Fields.INNER_HITS));
    parser.declareStringArray((map, list) -> map.put(Fields.MATCHED_QUERIES, list), new ParseField(Fields.MATCHED_QUERIES));
    parser.declareField((map, list) -> map.put(Fields.SORT, list), SearchSortValues::fromXContent, new ParseField(Fields.SORT), ValueType.OBJECT_ARRAY);
}
Also used : DocumentField(org.opensearch.common.document.DocumentField) ParseField(org.opensearch.common.ParseField)

Example 9 with ParseField

use of org.opensearch.common.ParseField in project OpenSearch by opensearch-project.

the class ParsedStats method declareStatsFields.

protected static void declareStatsFields(ObjectParser<? extends ParsedStats, Void> objectParser) {
    declareAggregationFields(objectParser);
    objectParser.declareLong((agg, value) -> agg.count = value, new ParseField(Fields.COUNT));
    objectParser.declareField((agg, value) -> agg.min = value, (parser, context) -> parseDouble(parser, Double.POSITIVE_INFINITY), new ParseField(Fields.MIN), ValueType.DOUBLE_OR_NULL);
    objectParser.declareField((agg, value) -> agg.max = value, (parser, context) -> parseDouble(parser, Double.NEGATIVE_INFINITY), new ParseField(Fields.MAX), ValueType.DOUBLE_OR_NULL);
    objectParser.declareField((agg, value) -> agg.avg = value, (parser, context) -> parseDouble(parser, 0), new ParseField(Fields.AVG), ValueType.DOUBLE_OR_NULL);
    objectParser.declareField((agg, value) -> agg.sum = value, (parser, context) -> parseDouble(parser, 0), new ParseField(Fields.SUM), ValueType.DOUBLE_OR_NULL);
    objectParser.declareString((agg, value) -> agg.valueAsString.put(Fields.MIN_AS_STRING, value), new ParseField(Fields.MIN_AS_STRING));
    objectParser.declareString((agg, value) -> agg.valueAsString.put(Fields.MAX_AS_STRING, value), new ParseField(Fields.MAX_AS_STRING));
    objectParser.declareString((agg, value) -> agg.valueAsString.put(Fields.AVG_AS_STRING, value), new ParseField(Fields.AVG_AS_STRING));
    objectParser.declareString((agg, value) -> agg.valueAsString.put(Fields.SUM_AS_STRING, value), new ParseField(Fields.SUM_AS_STRING));
}
Also used : ParseField(org.opensearch.common.ParseField)

Example 10 with ParseField

use of org.opensearch.common.ParseField in project job-scheduler by opensearch-project.

the class JobSchedulerPlugin method getNamedXContent.

public List<NamedXContentRegistry.Entry> getNamedXContent() {
    List<NamedXContentRegistry.Entry> registryEntries = new ArrayList<>();
    // register schedule
    NamedXContentRegistry.Entry scheduleEntry = new NamedXContentRegistry.Entry(Schedule.class, new ParseField("schedule"), ScheduleParser::parse);
    registryEntries.add(scheduleEntry);
    return registryEntries;
}
Also used : ScheduleParser(org.opensearch.jobscheduler.spi.schedule.ScheduleParser) ArrayList(java.util.ArrayList) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ParseField(org.opensearch.common.ParseField)

Aggregations

ParseField (org.opensearch.common.ParseField)66 NamedObjectParser (org.opensearch.common.xcontent.ObjectParser.NamedObjectParser)26 Matchers.containsString (org.hamcrest.Matchers.containsString)15 List (java.util.List)14 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)9 Map (java.util.Map)7 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)6 Aggregation (org.opensearch.search.aggregations.Aggregation)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 UncheckedIOException (java.io.UncheckedIOException)5 HashMap (java.util.HashMap)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 JsonXContent (org.opensearch.common.xcontent.json.JsonXContent)4 Collections (java.util.Collections)3 OpenSearchException (org.opensearch.OpenSearchException)3 ExplainResponse (org.opensearch.action.explain.ExplainResponse)3 NamedObject (org.opensearch.common.xcontent.ObjectParserTests.NamedObject)3 XContentParser (org.opensearch.common.xcontent.XContentParser)3 URI (java.net.URI)2