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


Java IndexRequestBuilder.setSource方法代码示例

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


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

示例1: pushSpanToBulkRequest

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
/**
 * 存储到ES
 * 
 * @param appUUID
 * @param span
 * @param bulkRequest
 */
private void pushSpanToBulkRequest(String appUUID, String appGroup, Span span, BulkRequestBuilder bulkRequest) {

    /**
     * 保证不会重复
     */
    String uuid = EncodeHelper.encodeMD5(span.toString());

    /**
     * 获取当前正在使用的index名称
     */
    String currentIndex = indexMgr.prepareIndex();

    IndexRequestBuilder irb = client.getClient().prepareIndex(currentIndex, InvokeChainIndexMgr.IVC_Table, uuid);

    Map<String, Object> m = span.toMap();

    m.put("appuuid", appUUID);
    m.put("appgroup", appGroup);

    irb.setSource(m);

    bulkRequest.add(irb);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:31,代码来源:InvokeChainDataCollectHandler.java

示例2: canIndexDocument

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
private void canIndexDocument(String index) {
    try {
        IndexRequestBuilder builder = client().prepareIndex(index, "zzz");
        builder.setSource("foo", "bar");
        IndexResponse r = builder.execute().actionGet();
        assertThat(r, notNullValue());
    } catch (ClusterBlockException e) {
        fail();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:SimpleBlocksIT.java

示例3: pushDataToBulkRequest

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
/**
 * 
 * @param appUUID
 * @param appGroup
 * @param span
 * @param bulkRequest
 */
private void pushDataToBulkRequest(JavaThreadObject jto, BulkRequestBuilder bulkRequest) {

    /**
     * 保证不会重复
     */
    String uuid = EncodeHelper.encodeMD5(jto.toString());

    /**
     * 获取当前正在使用的index名称
     */
    String currentIndex = indexMgr.prepareIndex();

    IndexRequestBuilder irb = client.getClient().prepareIndex(currentIndex, ThreadAnalysisIndexMgr.JTA_TABLE, uuid);

    Map<String, Object> m = jto.toMap();

    irb.setSource(m);

    bulkRequest.add(irb);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:28,代码来源:ThreadAnalysisCollectDataHandler.java

示例4: canNotIndexDocument

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
private void canNotIndexDocument(String index) {
    try {
        IndexRequestBuilder builder = client().prepareIndex(index, "zzz");
        builder.setSource("foo", "bar");
        builder.execute().actionGet();
        fail();
    } catch (ClusterBlockException e) {
        // all is well
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:SimpleBlocksIT.java

示例5: pushSpanToBulkRequest

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
/**
 * 存储到ES
 * 
 * @param appUUID
 * @param appGroup
 * @param span
 * @param bulkRequest
 * @param protocolType
 */
private void pushSpanToBulkRequest(String appUUID, String appGroup, SlowOperSpan span,
        BulkRequestBuilder bulkRequest, String protocolType) {

    /**
     * 保证不会重复(其实是防止重复读取时数据重复)
     */
    String uuid = EncodeHelper.encodeMD5(span.toString());

    /**
     * 获取当前正在使用的index名称
     */
    String currentIndex = indexMgr.prepareIndex(span.getAppid());
    /**
     * 准备对应type
     */
    indexMgr.prepareIndexType(currentIndex, protocolType);

    IndexRequestBuilder irb = client.getClient().prepareIndex(currentIndex, protocolType, uuid);

    Map<String, Object> m = span.toMap();

    // 暂时保留这两个属性
    m.put("appuuid", appUUID);
    m.put("appgroup", appGroup);

    irb.setSource(m);

    bulkRequest.add(irb);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:39,代码来源:SlowOperDataCollectHandler.java

示例6: create

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
private TestContext create(SearchType... searchTypes) throws Exception {
    assertAcked(prepareCreate("index").addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties")
            .startObject("field1")
                .field("type", "long")
            .endObject()
            .startObject("field2")
                .field("type", "keyword")
            .endObject()
            .startObject("nested")
                .field("type", "nested")
                .startObject("properties")
                    .startObject("field3")
                        .field("type", "long")
                    .endObject()
                    .startObject("field4")
                        .field("type", "keyword")
                    .endObject()
                .endObject()
            .endObject()
            .endObject().endObject().endObject()));

    int numDocs = 2 + randomInt(512);
    int scrollRequestSize = randomIntBetween(1, rarely() ? numDocs : numDocs / 2);
    boolean unevenRouting = randomBoolean();

    int numMissingDocs = scaledRandomIntBetween(0, numDocs / 100);
    IntHashSet missingDocs = new IntHashSet(numMissingDocs);
    for (int i = 0; i < numMissingDocs; i++) {
        while (!missingDocs.add(randomInt(numDocs))) {}
    }

    for (int i = 1; i <= numDocs; i++) {
        IndexRequestBuilder indexRequestBuilder = client()
                .prepareIndex("index", "type", String.valueOf(i));
        if (missingDocs.contains(i)) {
            indexRequestBuilder.setSource("x", "y");
        } else {
            indexRequestBuilder.setSource(jsonBuilder().startObject()
                    .field("field1", i)
                    .field("field2", String.valueOf(i))
                    .startObject("nested")
                        .field("field3", i)
                        .field("field4", String.valueOf(i))
                    .endObject()
                    .endObject());
        }

        if (unevenRouting && randomInt(3) <= 2) {
            indexRequestBuilder.setRouting("a");
        }
        indexRandom(false, indexRequestBuilder);
    }
    refresh();

    final SortBuilder sort;
    if (randomBoolean()) {
        if (randomBoolean()) {
            sort = SortBuilders.fieldSort("field1").missing(1);
        } else {
            sort = SortBuilders.fieldSort("field2")
                    .missing("1");
        }
    } else {
        if (randomBoolean()) {
            sort = SortBuilders.fieldSort("nested.field3").missing(1);
        } else {
            sort = SortBuilders.fieldSort("nested.field4").missing("1");
        }
    }
    sort.order(randomBoolean() ? SortOrder.ASC : SortOrder.DESC);

    SearchType searchType = RandomPicks.randomFrom(random(), Arrays.asList(searchTypes));

    logger.info("numDocs={}, scrollRequestSize={}, sort={}, searchType={}", numDocs, scrollRequestSize, sort, searchType);
    return new TestContext(numDocs, scrollRequestSize, sort, searchType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:77,代码来源:DuelScrollIT.java

示例7: pushLogLineToBulkRequest

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
/**
 * pushLogLineToBulkRequest
 * 
 * @param mdf
 * @param appid
 * @param bulkRequest
 * @param logData
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private void pushLogLineToBulkRequest(MonitorDataFrame mdf, String appid, String ipport,
        BulkRequestBuilder bulkRequest, Map logData) {

    /**
     * Step 1: get log file name
     */
    String logid = (String) logData.get("id");

    File f = new File(logid);

    String logFileName = f.getName().replace('.', '_');

    /**
     * Step 2: read log file lines
     */
    Map<String, Object> fields = (Map<String, Object>) logData.get("values");

    List<Map> lines = (List<Map>) fields.get("content");

    for (Map line : lines) {

        long ts = DataConvertHelper.toLong(line.get("_timestamp"), -1);

        line.remove("_timestamp");
        line.put("l_timestamp", ts);

        long lnum = DataConvertHelper.toLong(line.get("_lnum"), -1);

        line.remove("_lnum");
        line.put("l_num", lnum);

        /**
         * 如果没有规则设置,使用了全行抓取,则索引Type=日志文件名+"_def"
         */
        String logFileType = logFileName;
        StringBuilder uuidStr = new StringBuilder();
        uuidStr.append(ipport).append(mdf.getServerId()).append("-").append(appid).append("-").append(logid);
        if (line.containsKey("content")) {
            logFileType += "_def";
            uuidStr.append("-").append(line.get("content"));
        }
        /**
         * 如果设置了规则,则应该使用索引Type=日志文件名+"_"+<规则名>
         */
        else {
            // TODO: not implement yet
        }

        /**
         * 保证不重复:IP+SvrID+AppID+LogFileName+日志内容(def下为content)
         */
        String uuid = EncodeHelper.encodeMD5(uuidStr.toString());

        // 准备index,如果不存在,就创建
        String currentIndex = indexMgr.prepareIndex(appid);

        // 检查type是否存在,不存在就创建
        indexMgr.prepareIndexType(currentIndex, logFileType.toLowerCase());

        IndexRequestBuilder irb = client.getClient().prepareIndex(currentIndex, logFileType.toLowerCase(), uuid);

        /**
         * 用于区分不同机器上的应用实例
         */
        line.put("ipport", ipport);

        irb.setSource(line);

        bulkRequest.add(irb);
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:81,代码来源:NewLogDataMessageHandler.java

示例8: main

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
public static void main(String[] args) {

        TransportClient client = new PreBuiltTransportClient(Settings.EMPTY);

        client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));

        IndexRequestBuilder irb = client.prepareIndex("uav_test_db", "uav_test_table");

        Map<String, Object> item = new HashMap<String, Object>();

        item.put("name", "zz");
        item.put("age", 1);

        irb.setSource(item);

        IndexResponse ir = irb.get();

        System.out.println(ir.status());

        client.close();
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:22,代码来源:DoTestESClient.java


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