Java Code Examples for org.elasticsearch.common.xcontent.XContentHelper#toMap()

The following examples show how to use org.elasticsearch.common.xcontent.XContentHelper#toMap() . 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: GeneratedColsFromRawInsertSource.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Object> generateSourceAndCheckConstraints(Object[] values) {
    String rawSource = (String) values[0];
    Map<String, Object> source = XContentHelper.toMap(new BytesArray(rawSource), XContentType.JSON);
    mixinDefaults(source, defaults);
    for (int i = 0; i < expressions.size(); i++) {
        expressions.get(i).setNextRow(source);
    }
    for (Map.Entry<Reference, Input<?>> entry : generatedCols.entrySet()) {
        var reference = entry.getKey();
        var value = entry.getValue().value();
        var valueForInsert = reference
            .valueType()
            .valueForInsert(value);
        source.putIfAbsent(reference.column().fqn(), valueForInsert);
    }
    return source;
}
 
Example 2
Source File: PKLookupOperation.java    From crate with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Doc lookupDoc(IndexShard shard, String id, long version, VersionType versionType, long seqNo, long primaryTerm) {
    Term uidTerm = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
    Engine.Get get = new Engine.Get(id, uidTerm)
        .version(version)
        .versionType(versionType)
        .setIfSeqNo(seqNo)
        .setIfPrimaryTerm(primaryTerm);

    try (Engine.GetResult getResult = shard.get(get)) {
        var docIdAndVersion = getResult.docIdAndVersion();
        if (docIdAndVersion == null) {
            return null;
        }
        SourceFieldVisitor visitor = new SourceFieldVisitor();
        try {
            docIdAndVersion.reader.document(docIdAndVersion.docId, visitor);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
        return new Doc(
            docIdAndVersion.docId,
            shard.shardId().getIndexName(),
            id,
            docIdAndVersion.version,
            docIdAndVersion.seqNo,
            docIdAndVersion.primaryTerm,
            XContentHelper.toMap(visitor.source(), XContentType.JSON),
            () -> visitor.source().utf8ToString()
        );
    }
}
 
Example 3
Source File: LineContext.java    From crate with Apache License 2.0 5 votes vote down vote up
@Nullable
Map<String, Object> sourceAsMap() {
    if (parsedSource == null) {
        if (rawSource != null) {
            try {
                parsedSource = XContentHelper.toMap(new BytesArray(rawSource), XContentType.JSON);
            } catch (ElasticsearchParseException | NotXContentException e) {
                throw new RuntimeException("JSON parser error: " + e.getMessage(), e);
            }
        }
    }
    return parsedSource;
}
 
Example 4
Source File: SourceLookup.java    From crate with Apache License 2.0 4 votes vote down vote up
private void ensureSourceParsed() {
    if (source == null) {
        ensureDocVisited();
        source = XContentHelper.toMap(fieldsVisitor.source(), XContentType.JSON);
    }
}