當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。