本文整理汇总了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;
}
示例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");
}
示例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");
}
示例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;
}
示例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();
}
}