当前位置: 首页>>代码示例>>Java>>正文


Java XContentHelper.convertToJson方法代码示例

本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentHelper.convertToJson方法的典型用法代码示例。如果您正苦于以下问题:Java XContentHelper.convertToJson方法的具体用法?Java XContentHelper.convertToJson怎么用?Java XContentHelper.convertToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.xcontent.XContentHelper的用法示例。


在下文中一共展示了XContentHelper.convertToJson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testExecute

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testExecute() throws Exception {
    String processorTag = randomAsciiOfLength(3);
    String randomField = randomAsciiOfLength(3);
    String randomTargetField = randomAsciiOfLength(2);
    JsonProcessor jsonProcessor = new JsonProcessor(processorTag, randomField, randomTargetField, false);
    Map<String, Object> document = new HashMap<>();

    Map<String, Object> randomJsonMap = RandomDocumentPicks.randomSource(random());
    XContentBuilder builder = JsonXContent.contentBuilder().map(randomJsonMap);
    String randomJson = XContentHelper.convertToJson(builder.bytes(), false);
    document.put(randomField, randomJson);

    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
    jsonProcessor.execute(ingestDocument);
    Map<String, Object> jsonified = ingestDocument.getFieldValue(randomTargetField, Map.class);
    assertIngestDocument(ingestDocument.getFieldValue(randomTargetField, Object.class), jsonified);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:JsonProcessorTests.java

示例2: parseSource

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
public void parseSource(BytesReference source) throws SQLParseException {
    XContentParser parser = null;
    try {
        if (source != null && source.length() != 0) {
            parser = XContentFactory.xContent(source).createParser(source);
            parse(parser);
        }
        validate();
    } catch (Exception e) {
        String sSource = "_na_";
        try {
            sSource = XContentHelper.convertToJson(source, false);
        } catch (Throwable e1) {
            // ignore
        }
        throw new SQLParseException("Failed to parse source [" + sSource + "]", e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:SQLXContentSourceParser.java

示例3: getSourceAsString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
/**
 * The source of the document as string (can be <tt>null</tt>).
 */
public String getSourceAsString() {
    if (source == null) {
        return null;
    }
    try {
        return XContentHelper.convertToJson(getSourceRef(), false);
    } catch (IOException e) {
        throw new ElasticsearchParseException("failed to convert source to a json string");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:SearchHit.java

示例4: source

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
/**
 * The mapping source definition.
 */
public PutMappingRequest source(BytesReference mappingSource, XContentType xContentType) {
    Objects.requireNonNull(xContentType);
    try {
        this.source = XContentHelper.convertToJson(mappingSource, false, false, xContentType);
        return this;
    } catch (IOException e) {
        throw new UncheckedIOException("failed to convert source to json", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:PutMappingRequest.java

示例5: readFrom

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    indices = in.readStringArray();
    indicesOptions = IndicesOptions.readIndicesOptions(in);
    type = in.readOptionalString();
    source = in.readString();
    if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO change to V_5_3 once backported
        // we do not know the format from earlier versions so convert if necessary
        source = XContentHelper.convertToJson(new BytesArray(source), false, false, XContentFactory.xContentType(source));
    }
    updateAllTypes = in.readBoolean();
    readTimeout(in);
    concreteIndex = in.readOptionalWriteable(Index::new);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:PutMappingRequest.java

示例6: toString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String toString() {
    String source = "_na_";

    try {
        source = XContentHelper.convertToJson(content, false, xContentType);
    } catch (Exception e) {
        // ignore
    }

    return "put stored script {id [" + id + "]" + (lang != null ? ", lang [" + lang + "]" : "") + ", content [" + source + "]}";
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:PutStoredScriptRequest.java

示例7: toString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String toString() {
    String sSource = "_na_";
    try {
        if (source.length() > MAX_SOURCE_LENGTH_IN_TOSTRING) {
            sSource = "n/a, actual length: [" + new ByteSizeValue(source.length()).toString() + "], max length: " +
                new ByteSizeValue(MAX_SOURCE_LENGTH_IN_TOSTRING).toString();
        } else {
            sSource = XContentHelper.convertToJson(source, false);
        }
    } catch (Exception e) {
        // ignore
    }
    return "index {[" + index + "][" + type + "][" + id + "], source[" + sSource + "]}";
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:IndexRequest.java

示例8: sourceAsString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String sourceAsString() {
    if (source == null) {
        return null;
    }
    try {
        return XContentHelper.convertToJson(sourceRef(), false);
    } catch (IOException e) {
        throw new ElasticsearchParseException("failed to convert source to a json string");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:InternalSearchHit.java

示例9: toString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String toString() {
    String sSource = "_na_";
    try {
        sSource = XContentHelper.convertToJson(source, false);
    } catch (Exception e) {
        // ignore
    }
    return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", source[" + sSource + "]";
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:ExistsRequest.java

示例10: toString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String toString() {
    if (sourceBuilder != null) {
        return sourceBuilder.toString();
    }
    if (request.source() != null) {
        try {
            return XContentHelper.convertToJson(request.source().toBytesArray(), false, true);
        } catch (Exception e) {
            return "{ \"error\" : \"" + ExceptionsHelper.detailedMessage(e) + "\"}";
        }
    }
    return new QuerySourceBuilder().toString();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:CountRequestBuilder.java

示例11: toString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String toString() {
    String sSource = "_na_";
    try {
        sSource = XContentHelper.convertToJson(source, false);
    } catch (Exception e) {
        // ignore
    }
    return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", source[" + sSource + "], explain:" + explain + 
            ", rewrite:" + rewrite;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:ValidateQueryRequest.java

示例12: toString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String toString() {
    String sSource = "_na_";
    try {
        sSource = XContentHelper.convertToJson(source, false);
    } catch (Exception e) {
        // ignore
    }
    return "index {[" + ScriptService.SCRIPT_INDEX + "][" + scriptLang + "][" + id + "], source[" + sSource + "]}";
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:PutIndexedScriptRequest.java

示例13: toString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String toString() {
    if (sourceBuilder != null) {
        return sourceBuilder.toString();
    }
    if (request.source() != null) {
        try {
            return XContentHelper.convertToJson(request.source().toBytesArray(), false, true);
        } catch (Exception e) {
            return "{ \"error\" : \"" + ExceptionsHelper.detailedMessage(e) + "\"}";
        }
    }
    return new SearchSourceBuilder().toString();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:SearchRequestBuilder.java

示例14: toString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String toString() {
    String sSource = "_na_";
    try {
        sSource = XContentHelper.convertToJson(suggestSource, false);
    } catch (Exception e) {
        // ignore
    }
    return "[" + Arrays.toString(indices) + "]" + ", suggestSource[" + sSource + "]";
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:SuggestRequest.java

示例15: toString

import org.elasticsearch.common.xcontent.XContentHelper; //导入方法依赖的package包/类
@Override
public String toString() {
    String sSource = "_na_";
    try {
        sSource = XContentHelper.convertToJson(searchRequest.source(), false);
    } catch (IOException e) {
        // ignore
    }
    return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types()) + ", source[" + sSource + "]";
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:DfsOnlyRequest.java


注:本文中的org.elasticsearch.common.xcontent.XContentHelper.convertToJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。