本文整理汇总了Java中org.elasticsearch.action.update.UpdateRequest.docAsUpsert方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateRequest.docAsUpsert方法的具体用法?Java UpdateRequest.docAsUpsert怎么用?Java UpdateRequest.docAsUpsert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.update.UpdateRequest
的用法示例。
在下文中一共展示了UpdateRequest.docAsUpsert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: should_use_doc_as_upsert
import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
@Test
public void should_use_doc_as_upsert() throws Exception {
BytesReference source = source().bytes();
Map<String, Object> expected = SourceLookup.sourceAsMap(source);
UpdateRequest updateRequest = new UpdateRequest(THE_INDEX, THE_TYPE, THE_ID).doc(source.toBytes());
updateRequest.docAsUpsert(true);
UpdateResponse updateResponse = httpClient.update(updateRequest).get();
Assertions.assertThat(updateResponse.getIndex()).isEqualTo(THE_INDEX);
Assertions.assertThat(updateResponse.getType()).isEqualTo(THE_TYPE);
Assertions.assertThat(updateResponse.getId()).isEqualTo(THE_ID);
Assertions.assertThat(updateResponse.getVersion()).isEqualTo(1);
Assertions.assertThat(updateResponse.isCreated()).isTrue();
Map<String, Object> actualSource = get(THE_INDEX, THE_TYPE, THE_ID).getSource();
compareMap(expected, actualSource);
}
示例2: should_marshall_update_request_with_doc_as_upsert
import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
@Test
public void should_marshall_update_request_with_doc_as_upsert() throws Exception {
UpdateRequest request = new UpdateRequest();
request.index("the_index");
request.type("the_type");
request.id("the_id");
request.doc("bar", "baz");
request.docAsUpsert(true);
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("{\"doc_as_upsert\":true,\"doc\":{\"bar\":\"baz\"}}");
bytes = takeNth(observable, 3);
assertThat(new String(bytes)).isEqualTo("\n");
}
示例3: addElementToBulkRequest
import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
public void addElementToBulkRequest(Graph graph, BulkRequest bulkRequest, IndexInfo indexInfo, Element element, Authorizations authorizations) {
try {
XContentBuilder json = buildJsonContentFromElement(graph, element, authorizations);
UpdateRequest indexRequest = new UpdateRequest(indexInfo.getIndexName(), ELEMENT_TYPE, element.getId()).doc(json);
indexRequest.retryOnConflict(MAX_RETRIES);
indexRequest.docAsUpsert(true);
bulkRequest.add(indexRequest);
} catch (IOException ex) {
throw new MemgraphException("Could not add element to bulk request", ex);
}
}
示例4: addElementToBulkRequest
import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
public void addElementToBulkRequest(Graph graph, BulkRequest bulkRequest, IndexInfo indexInfo, Element element, Authorizations authorizations) {
try {
XContentBuilder json = buildJsonContentFromElement(graph, element, authorizations);
UpdateRequest indexRequest = new UpdateRequest(indexInfo.getIndexName(), ELEMENT_TYPE, element.getId()).doc(json);
indexRequest.retryOnConflict(MAX_RETRIES);
indexRequest.docAsUpsert(true);
bulkRequest.add(indexRequest);
} catch (IOException ex) {
throw new VertexiumException("Could not add element to bulk request", ex);
}
}
示例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();
}
}
示例6: prepareRequest
import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
UpdateRequest updateRequest = new UpdateRequest(request.param("index"), request.param("type"), request.param("id"));
updateRequest.routing(request.param("routing"));
updateRequest.parent(request.param("parent"));
updateRequest.timeout(request.paramAsTime("timeout", updateRequest.timeout()));
updateRequest.setRefreshPolicy(request.param("refresh"));
String waitForActiveShards = request.param("wait_for_active_shards");
if (waitForActiveShards != null) {
updateRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
}
updateRequest.docAsUpsert(request.paramAsBoolean("doc_as_upsert", updateRequest.docAsUpsert()));
FetchSourceContext fetchSourceContext = FetchSourceContext.parseFromRestRequest(request);
String sField = request.param("fields");
if (sField != null && fetchSourceContext != null) {
throw new IllegalArgumentException("[fields] and [_source] cannot be used in the same request");
}
if (sField != null) {
DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
String[] sFields = Strings.splitStringByCommaToArray(sField);
updateRequest.fields(sFields);
} else if (fetchSourceContext != null) {
updateRequest.fetchSource(fetchSourceContext);
}
updateRequest.retryOnConflict(request.paramAsInt("retry_on_conflict", updateRequest.retryOnConflict()));
updateRequest.version(RestActions.parseVersion(request));
updateRequest.versionType(VersionType.fromString(request.param("version_type"), updateRequest.versionType()));
request.applyContentParser(parser -> {
updateRequest.fromXContent(parser);
IndexRequest upsertRequest = updateRequest.upsertRequest();
if (upsertRequest != null) {
upsertRequest.routing(request.param("routing"));
upsertRequest.parent(request.param("parent"));
upsertRequest.version(RestActions.parseVersion(request));
upsertRequest.versionType(VersionType.fromString(request.param("version_type"), upsertRequest.versionType()));
}
IndexRequest doc = updateRequest.doc();
if (doc != null) {
doc.routing(request.param("routing"));
doc.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing
doc.version(RestActions.parseVersion(request));
doc.versionType(VersionType.fromString(request.param("version_type"), doc.versionType()));
}
});
return channel ->
client.update(updateRequest, new RestStatusToXContentListener<>(channel, r -> r.getLocation(updateRequest.routing())));
}