本文整理汇总了Java中org.elasticsearch.client.Requests.bulkRequest方法的典型用法代码示例。如果您正苦于以下问题:Java Requests.bulkRequest方法的具体用法?Java Requests.bulkRequest怎么用?Java Requests.bulkRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.client.Requests
的用法示例。
在下文中一共展示了Requests.bulkRequest方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareRequest
import org.elasticsearch.client.Requests; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
BulkRequest bulkRequest = Requests.bulkRequest();
String defaultIndex = request.param("index");
String defaultType = request.param("type");
String defaultRouting = request.param("routing");
String fieldsParam = request.param("fields");
String defaultPipeline = request.param("pipeline");
String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;
String waitForActiveShards = request.param("wait_for_active_shards");
if (waitForActiveShards != null) {
bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
}
bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
bulkRequest.setRefreshPolicy(request.param("refresh"));
bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields, null, defaultPipeline, null, true,
request.getXContentType());
// short circuit the call to the transport layer
return channel -> {
BulkRestBuilderListener listener = new BulkRestBuilderListener(channel, request);
listener.onResponse(bulkRequest);
};
}
示例2: prepareRequest
import org.elasticsearch.client.Requests; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
BulkRequest bulkRequest = Requests.bulkRequest();
String defaultIndex = request.param("index");
String defaultType = request.param("type");
String defaultRouting = request.param("routing");
FetchSourceContext defaultFetchSourceContext = FetchSourceContext.parseFromRestRequest(request);
String fieldsParam = request.param("fields");
if (fieldsParam != null) {
DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
}
String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;
String defaultPipeline = request.param("pipeline");
String waitForActiveShards = request.param("wait_for_active_shards");
if (waitForActiveShards != null) {
bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
}
bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
bulkRequest.setRefreshPolicy(request.param("refresh"));
bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields,
defaultFetchSourceContext, defaultPipeline, null, allowExplicitIndex, request.getXContentType());
return channel -> client.bulk(bulkRequest, new RestStatusToXContentListener<>(channel));
}
示例3: testBulkAddIterable
import org.elasticsearch.client.Requests; //导入方法依赖的package包/类
public void testBulkAddIterable() {
BulkRequest bulkRequest = Requests.bulkRequest();
List<DocWriteRequest> requests = new ArrayList<>();
requests.add(new IndexRequest("test", "test", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"));
requests.add(new UpdateRequest("test", "test", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"));
requests.add(new DeleteRequest("test", "test", "id"));
bulkRequest.add(requests);
assertThat(bulkRequest.requests().size(), equalTo(3));
assertThat(bulkRequest.requests().get(0), instanceOf(IndexRequest.class));
assertThat(bulkRequest.requests().get(1), instanceOf(UpdateRequest.class));
assertThat(bulkRequest.requests().get(2), instanceOf(DeleteRequest.class));
}
示例4: save
import org.elasticsearch.client.Requests; //导入方法依赖的package包/类
@Override
public void save(List<Document> data) {
if (data != null) {
BulkRequest bulkRequest = Requests.bulkRequest();
data.forEach(item -> {
bulkRequest.add(Requests.indexRequest(index).type(type).id(item.getId()).source(data));
});
client.bulk(bulkRequest).actionGet();
}
}
示例5: updateCanonicalIds
import org.elasticsearch.client.Requests; //导入方法依赖的package包/类
public void updateCanonicalIds(Id canonicalId, Iterable<Id> setIds) throws IndexException {
ImmutableSet<GetResponse> setSources = resolveSet(setIds);
BulkRequest bulkReq = Requests.bulkRequest();
for (GetResponse response : setSources) {
Map<String, Object> source = response.getSourceAsMap();
if (source != null) {
source.put(EsContent.CANONICAL_ID, canonicalId.longValue());
IndexRequest req = Requests.indexRequest(indexName)
.id(Integer.toString((int) response.getSourceAsMap().get(EsContent.ID)))
.type(response.getType())
.source(response.getSourceAsMap());
if (response.getType().equalsIgnoreCase(EsContent.CHILD_ITEM)) {
req.parent(String.valueOf(source.get(EsContent.BRAND)));
}
bulkReq.add(req);
}
}
if (bulkReq.numberOfActions() > 0) {
BulkResponse resp = ElasticsearchUtils.getWithTimeout(
esClient.bulk(bulkReq),
requestTimeout
);
if (resp.hasFailures()) {
throw new IndexException("Failures occurred while bulk updating canonical IDs: "
+ resp.buildFailureMessage());
}
}
}
示例6: handleRequest
import org.elasticsearch.client.Requests; //导入方法依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
BulkRequest bulkRequest = Requests.bulkRequest();
String defaultIndex = request.param("index");
String defaultType = request.param("type");
String defaultRouting = request.param("routing");
String fieldsParam = request.param("fields");
String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;
String consistencyLevel = request.param("consistency");
if (consistencyLevel != null) {
bulkRequest.consistencyLevel(WriteConsistencyLevel.fromString(consistencyLevel));
}
bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
bulkRequest.refresh(request.paramAsBoolean("refresh", bulkRequest.refresh()));
bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields, null, allowExplicitIndex);
client.bulk(bulkRequest, new RestBuilderListener<BulkResponse>(channel) {
@Override
public RestResponse buildResponse(BulkResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
builder.field(Fields.TOOK, response.getTookInMillis());
builder.field(Fields.ERRORS, response.hasFailures());
builder.startArray(Fields.ITEMS);
for (BulkItemResponse itemResponse : response) {
builder.startObject();
builder.startObject(itemResponse.getOpType());
builder.field(Fields._INDEX, itemResponse.getIndex());
builder.field(Fields._TYPE, itemResponse.getType());
builder.field(Fields._ID, itemResponse.getId());
long version = itemResponse.getVersion();
if (version != -1) {
builder.field(Fields._VERSION, itemResponse.getVersion());
}
if (itemResponse.isFailed()) {
builder.field(Fields.STATUS, itemResponse.getFailure().getStatus().getStatus());
builder.startObject(Fields.ERROR);
ElasticsearchException.toXContent(builder, request, itemResponse.getFailure().getCause());
builder.endObject();
} else {
ActionWriteResponse.ShardInfo shardInfo = itemResponse.getResponse().getShardInfo();
shardInfo.toXContent(builder, request);
if (itemResponse.getResponse() instanceof DeleteResponse) {
DeleteResponse deleteResponse = itemResponse.getResponse();
if (deleteResponse.isFound()) {
builder.field(Fields.STATUS, shardInfo.status().getStatus());
} else {
builder.field(Fields.STATUS, RestStatus.NOT_FOUND.getStatus());
}
builder.field(Fields.FOUND, deleteResponse.isFound());
} else if (itemResponse.getResponse() instanceof IndexResponse) {
IndexResponse indexResponse = itemResponse.getResponse();
if (indexResponse.isCreated()) {
builder.field(Fields.STATUS, RestStatus.CREATED.getStatus());
} else {
builder.field(Fields.STATUS, shardInfo.status().getStatus());
}
} else if (itemResponse.getResponse() instanceof UpdateResponse) {
UpdateResponse updateResponse = itemResponse.getResponse();
if (updateResponse.isCreated()) {
builder.field(Fields.STATUS, RestStatus.CREATED.getStatus());
} else {
builder.field(Fields.STATUS, shardInfo.status().getStatus());
}
if (updateResponse.getGetResult() != null) {
builder.startObject(Fields.GET);
updateResponse.getGetResult().toXContentEmbedded(builder, request);
builder.endObject();
}
}
}
builder.endObject();
builder.endObject();
}
builder.endArray();
builder.endObject();
return new BytesRestResponse(OK, builder);
}
});
}
示例7: indexItem
import org.elasticsearch.client.Requests; //导入方法依赖的package包/类
public void indexItem(Item item) {
try {
EsContent esContent = contentTranslator.toEsContent(item);
BulkRequest requests = Requests.bulkRequest();
IndexRequest mainIndexRequest;
ContainerRef container = item.getContainerRef();
if (item instanceof Episode && ((Episode) item).getSeriesRef() != null) {
Episode episode = (Episode) item;
Optional<Map<String, Object>> maybeParent = getContainer(episode.getSeriesRef());
if (maybeParent.isPresent()) {
Map<String, Object> series = contentTranslator.denormalizeEpisodeOntoSeries(
episode, maybeParent.get()
);
reindexParent(episode.getSeriesRef(), series);
}
}
if (container != null) {
contentTranslator.setParentFields(esContent, container);
mainIndexRequest = Requests.indexRequest(indexName)
.type(EsContent.CHILD_ITEM)
.id(getDocId(item))
.source(esContent.toMap())
.parent(getDocId(container));
log.debug(mainIndexRequest.source().toUtf8());
} else {
mainIndexRequest = Requests.indexRequest(indexName)
.type(EsContent.TOP_LEVEL_ITEM)
.id(getDocId(item))
.source(esContent.hasChildren(false).toMap());
log.debug(mainIndexRequest.source().toUtf8());
}
requests.add(mainIndexRequest);
BulkResponse resp = ElasticsearchUtils.getWithTimeout(
esClient.bulk(requests),
requestTimeout
);
log.debug("indexed {} ({}ms)", item, resp.getTookInMillis());
} catch (Exception e) {
throw new RuntimeIndexException("Error indexing " + item, e);
}
}