当前位置: 首页>>代码示例>>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;未经允许,请勿转载。