當前位置: 首頁>>代碼示例>>Java>>正文


Java UpdateRequest.script方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.update.UpdateRequest.script方法的典型用法代碼示例。如果您正苦於以下問題:Java UpdateRequest.script方法的具體用法?Java UpdateRequest.script怎麽用?Java UpdateRequest.script使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.update.UpdateRequest的用法示例。


在下文中一共展示了UpdateRequest.script方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: internalAdd

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
BulkRequest internalAdd(UpdateRequest request, @Nullable Object payload) {
    Objects.requireNonNull(request, "'request' must not be null");
    requests.add(request);
    addPayload(payload);
    if (request.doc() != null) {
        sizeInBytes += request.doc().source().length();
    }
    if (request.upsertRequest() != null) {
        sizeInBytes += request.upsertRequest().source().length();
    }
    if (request.script() != null) {
        sizeInBytes += request.script().getIdOrCode().length() * 2;
    }
    indices.add(request.index());
    return this;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:BulkRequest.java

示例2: should_marshall_update_request_with_script

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void should_marshall_update_request_with_script() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.script("the_script");
    Observable<byte[]> observable = BulkActionMarshaller.lazyConvertToBytes(Collections.<ActionRequest>singletonList(request));
    assertHasSize(observable, 4);

    byte[] bytes = takeNth(observable, 0);
    assertThat(new String(bytes)).isEqualTo("{\"update\":{\"_index\":\"the_index\",\"_type\":\"the_type\",\"_id\":\"the_id\",\"_retry_on_conflict\":0}}");

    bytes = takeNth(observable, 1);
    assertThat(new String(bytes)).isEqualTo("\n");

    bytes = takeNth(observable, 2);
    assertThat(new String(bytes)).isEqualTo("{\"script\":\"the_script\"}");

    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:23,代碼來源:BulkActionMarshallerTest.java

示例3: should_marshall_update_request_with_script_and_upsert

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void should_marshall_update_request_with_script_and_upsert() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.script("the_script");
    request.upsert("bar", "baz");
    Observable<byte[]> observable = BulkActionMarshaller.lazyConvertToBytes(Collections.<ActionRequest>singletonList(request));
    assertHasSize(observable, 4);

    byte[] bytes = takeNth(observable, 0);
    assertThat(new String(bytes)).isEqualTo("{\"update\":{\"_index\":\"the_index\",\"_type\":\"the_type\",\"_id\":\"the_id\",\"_retry_on_conflict\":0}}");

    bytes = takeNth(observable, 1);
    assertThat(new String(bytes)).isEqualTo("\n");

    bytes = takeNth(observable, 2);
    assertThat(new String(bytes)).isEqualTo("{\"upsert\":{\"bar\":\"baz\"},\"script\":\"the_script\"}");

    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:24,代碼來源:BulkActionMarshallerTest.java

示例4: internalAdd

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
BulkRequest internalAdd(UpdateRequest request, @Nullable Object payload) {
    requests.add(request);
    addPayload(payload);
    if (request.doc() != null) {
        sizeInBytes += request.doc().source().length();
    }
    if (request.upsertRequest() != null) {
        sizeInBytes += request.upsertRequest().source().length();
    }
    if (request.script() != null) {
        sizeInBytes += request.script().getScript().length() * 2;
    }
    return this;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:15,代碼來源:BulkRequest.java

示例5: buildRequestBody

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
public static byte[] buildRequestBody(UpdateRequest request) throws IOException {
    try (XContentBuilder requestBody = XContentFactory.jsonBuilder().startObject()) {
        boolean writeDoc = false;
        if (request.doc() != null) {
            writeDoc = true;
        }
        if (request.upsertRequest() != null) {
            // TODO lots of options on upsertRequest
            Map<String, Object> upsertAsMap = XContentHelper.convertToMap(request.upsertRequest().source(), false).v2();
            requestBody.field("upsert", upsertAsMap);
            addScriptParams(request, requestBody);
            if (request.scriptedUpsert()) {
                requestBody.field("scripted_upsert", request.scriptedUpsert());
            }
        } else if (request.docAsUpsert()) {
            // request.doc() may be null if there is only a script
            requestBody.field("doc_as_upsert", true);
            if (request.doc() != null) {
                writeDoc = true;
            }
        }
        if (request.script() != null) {
            requestBody.field("script", request.script());
            addScriptParams(request, requestBody);
        }

        if (writeDoc) {
            Map<String, Object> docAsMap = XContentHelper.convertToMap(request.doc().source(), false).v2();
            requestBody.field("doc", docAsMap);
        }

        if (request.detectNoop()) {
            requestBody.field("detect_noop", String.valueOf(request.detectNoop()));
        }
        return requestBody.endObject().bytes().toBytes();
    }
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:38,代碼來源:UpdateHelper.java


注:本文中的org.elasticsearch.action.update.UpdateRequest.script方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。