本文整理汇总了Java中org.elasticsearch.action.index.IndexRequest类的典型用法代码示例。如果您正苦于以下问题:Java IndexRequest类的具体用法?Java IndexRequest怎么用?Java IndexRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IndexRequest类属于org.elasticsearch.action.index包,在下文中一共展示了IndexRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: failureHandlerExecutesFailoverForEachBatchItemSeparately
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
@Test
public void failureHandlerExecutesFailoverForEachBatchItemSeparately() {
// given
Builder builder = createTestObjectFactoryBuilder();
ClientObjectFactory<TransportClient, BulkRequest> config = builder.build();
FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());
String payload1 = "test1";
String payload2 = "test2";
BulkRequest bulk = new BulkRequest()
.add(spy(new IndexRequest().source(payload1)))
.add(spy(new IndexRequest().source(payload2)));
// when
config.createFailureHandler(failoverPolicy).apply(bulk);
// then
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(failoverPolicy, times(2)).deliver((String) captor.capture());
assertTrue(captor.getAllValues().contains(payload1));
assertTrue(captor.getAllValues().contains(payload2));
}
示例2: failureHandlerExecutesFailoverForEachBatchItemSeparately
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
@Test
public void failureHandlerExecutesFailoverForEachBatchItemSeparately() {
// given
Builder builder = createTestObjectFactoryBuilder();
ClientObjectFactory<TransportClient, BulkRequest> config = builder.build();
FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy());
String payload1 = "test1";
String payload2 = "test2";
BulkRequest bulk = new BulkRequest()
.add(spy(new IndexRequest().source(payload1, XContentType.CBOR)))
.add(spy(new IndexRequest().source(payload2, XContentType.CBOR)));
// when
config.createFailureHandler(failoverPolicy).apply(bulk);
// then
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(failoverPolicy, times(2)).deliver((String) captor.capture());
assertTrue(captor.getAllValues().contains(payload1));
assertTrue(captor.getAllValues().contains(payload2));
}
示例3: process
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
@Override
public void process(DeviceEvent element, RuntimeContext ctx, RequestIndexer indexer) {
Map<String, Object> json = new HashMap<>();
json.put("phoneNumber", element.getPhoneNumber());
json.put("bin", element.getBin());
json.put("bout", element.getBout());
json.put("timestamp", element.getTimestamp());
System.out.println(json);
IndexRequest source = Requests.indexRequest()
.index("flink-test")
.type("flink-log")
.source(json);
indexer.add(source);
}
开发者ID:PacktPublishing,项目名称:Practical-Real-time-Processing-and-Analytics,代码行数:18,代码来源:FlinkESConnector.java
示例4: validateAgainstAliases
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
/**
* Throws an ActionRequestValidationException if the request tries to index
* back into the same index or into an index that points to two indexes.
* This cannot be done during request validation because the cluster state
* isn't available then. Package private for testing.
*/
static void validateAgainstAliases(SearchRequest source, IndexRequest destination, RemoteInfo remoteInfo,
IndexNameExpressionResolver indexNameExpressionResolver, AutoCreateIndex autoCreateIndex,
ClusterState clusterState) {
if (remoteInfo != null) {
return;
}
String target = destination.index();
if (false == autoCreateIndex.shouldAutoCreate(target, clusterState)) {
/*
* If we're going to autocreate the index we don't need to resolve
* it. This is the same sort of dance that TransportIndexRequest
* uses to decide to autocreate the index.
*/
target = indexNameExpressionResolver.concreteIndexNames(clusterState, destination)[0];
}
for (String sourceIndex : indexNameExpressionResolver.concreteIndexNames(clusterState, source)) {
if (sourceIndex.equals(target)) {
ActionRequestValidationException e = new ActionRequestValidationException();
e.addValidationError("reindex cannot write into an index its reading from [" + target + ']');
throw e;
}
}
}
示例5: handleSampleResults
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
@Override
public void handleSampleResults(List<SampleResult> results, BackendListenerContext context) {
for(SampleResult sr : results) {
this.bulkRequest.add(
new IndexRequest(this.index, "SampleResult").source(this.getElasticData(sr, context),
XContentType.JSON));
}
if(this.bulkRequest.numberOfActions() >= this.bulkSize) {
try {
sendRequest(bulkRequest);
} catch (Exception e) {
logger.error("Error sending data to ES, data will be lost", e);
} finally {
this.bulkRequest = new BulkRequest().timeout(TimeValue.timeValueMillis(timeoutMs));
}
}
}
示例6: enforceSameContentType
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
/**
* Ensure that the {@link IndexRequest}'s content type is supported by the Bulk API and that it conforms
* to the current {@link BulkRequest}'s content type (if it's known at the time of this method get called).
*
* @return the {@link IndexRequest}'s content type
*/
static XContentType enforceSameContentType(IndexRequest indexRequest, @Nullable XContentType xContentType) {
XContentType requestContentType = indexRequest.getContentType();
if (requestContentType != XContentType.JSON && requestContentType != XContentType.SMILE) {
throw new IllegalArgumentException("Unsupported content-type found for request with content-type [" + requestContentType
+ "], only JSON and SMILE are supported");
}
if (xContentType == null) {
return requestContentType;
}
if (requestContentType != xContentType) {
throw new IllegalArgumentException("Mismatching content-type found for request with content-type [" + requestContentType
+ "], previous requests have content-type [" + xContentType + "]");
}
return xContentType;
}
示例7: indexDoc
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
protected Engine.Index indexDoc(IndexShard shard, String type, String id, String source, XContentType xContentType) throws IOException {
final Engine.Index index;
if (shard.routingEntry().primary()) {
index = shard.prepareIndexOnPrimary(
SourceToParse.source(SourceToParse.Origin.PRIMARY, shard.shardId().getIndexName(), type, id, new BytesArray(source),
xContentType),
Versions.MATCH_ANY,
VersionType.INTERNAL,
IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP,
false);
} else {
index = shard.prepareIndexOnReplica(
SourceToParse.source(SourceToParse.Origin.PRIMARY, shard.shardId().getIndexName(), type, id, new BytesArray(source),
xContentType),
randomInt(1 << 10), 1, VersionType.EXTERNAL, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false);
}
shard.index(index);
return index;
}
示例8: prepareRequest
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
IndexRequest indexRequest = new IndexRequest(request.param("index"), request.param("type"), request.param("id"));
indexRequest.routing(request.param("routing"));
indexRequest.parent(request.param("parent"));
indexRequest.setPipeline(request.param("pipeline"));
indexRequest.source(request.content(), request.getXContentType());
indexRequest.timeout(request.paramAsTime("timeout", IndexRequest.DEFAULT_TIMEOUT));
indexRequest.setRefreshPolicy(request.param("refresh"));
indexRequest.version(RestActions.parseVersion(request));
indexRequest.versionType(VersionType.fromString(request.param("version_type"), indexRequest.versionType()));
String sOpType = request.param("op_type");
String waitForActiveShards = request.param("wait_for_active_shards");
if (waitForActiveShards != null) {
indexRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
}
if (sOpType != null) {
indexRequest.opType(sOpType);
}
return channel ->
client.index(indexRequest, new RestStatusToXContentListener<>(channel, r -> r.getLocation(indexRequest.routing())));
}
示例9: writeTo
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeByte(consistencyLevel.id());
out.writeVInt(requests.size());
for (ActionRequest request : requests) {
if (request instanceof IndexRequest) {
out.writeByte((byte) 0);
} else if (request instanceof DeleteRequest) {
out.writeByte((byte) 1);
} else if (request instanceof UpdateRequest) {
out.writeByte((byte) 2);
}
request.writeTo(out);
}
out.writeBoolean(refresh);
timeout.writeTo(out);
}
示例10: createWindowWordRanking
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
/**
* Creates a new Elasticsearch request from the given element.
* @param value the element to process.
* @return the Elasticsearch request.
*/
private IndexRequest createWindowWordRanking(PlayerGridStatistics value) {
String cellsJson = value.getStats().entrySet().stream()
.map(e -> "{" + "\"cid\":\"" + e.getKey() + "\",\"presence\":" + e.getValue() + "}")
.collect(Collectors.joining(","));
String json =
"{\"ts\":" + value.getTsStart() +
",\"pid\":" + value.getPid() +
",\"cells\":[" + cellsJson + "]}";
//LOG.debug("JSON: {}", json);
return Requests.indexRequest()
.index(this.indexName)
.type(this.typeName)
.source(json);
}
示例11: prepareIndexOnPrimary
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
private Engine.IndexingOperation prepareIndexOnPrimary(IndexShard indexShard,
long version,
ShardUpsertRequest request,
ShardUpsertRequest.Item item) {
SourceToParse sourceToParse = SourceToParse.source(SourceToParse.Origin.PRIMARY, item.source())
.type(request.type())
.id(item.id())
.routing(request.routing());
if (logger.isTraceEnabled()) {
logger.trace("[{}] shard operation with opType={} id={} version={} source={}",
indexShard.shardId(), item.opType(), item.id(), version, item.source().toUtf8());
}
if (item.opType() == IndexRequest.OpType.INDEX) {
return indexShard.prepareIndexOnPrimary(sourceToParse, version, item.versionType(), request.canHaveDuplicates());
}
return indexShard.prepareCreateOnPrimary(
sourceToParse, version, item.versionType(), request.canHaveDuplicates(), false);
}
示例12: testNoopUpdateReplicaRequest
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
public void testNoopUpdateReplicaRequest() throws Exception {
DocWriteRequest writeRequest = new IndexRequest("index", "type", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value");
BulkItemRequest replicaRequest = new BulkItemRequest(0, writeRequest);
DocWriteResponse noopUpdateResponse = new UpdateResponse(shardId, "index", "id", 0, DocWriteResponse.Result.NOOP);
BulkItemResultHolder noopResults = new BulkItemResultHolder(noopUpdateResponse, null, replicaRequest);
Translog.Location location = new Translog.Location(0, 0, 0);
BulkItemRequest[] items = new BulkItemRequest[0];
BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items);
Translog.Location newLocation = TransportShardBulkAction.updateReplicaRequest(noopResults,
DocWriteRequest.OpType.UPDATE, location, bulkShardRequest);
BulkItemResponse primaryResponse = replicaRequest.getPrimaryResponse();
// Basically nothing changes in the request since it's a noop
assertThat(newLocation, equalTo(location));
assertThat(primaryResponse.getItemId(), equalTo(0));
assertThat(primaryResponse.getId(), equalTo("id"));
assertThat(primaryResponse.getOpType(), equalTo(DocWriteRequest.OpType.UPDATE));
assertThat(primaryResponse.getResponse(), equalTo(noopUpdateResponse));
assertThat(primaryResponse.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOOP));
}
示例13: executeIndexRequestOnReplica
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
/**
* Execute the given {@link IndexRequest} on a replica shard, throwing a
* {@link RetryOnReplicaException} if the operation needs to be re-tried.
*/
public static Engine.IndexResult executeIndexRequestOnReplica(DocWriteResponse primaryResponse, IndexRequest request, IndexShard replica) throws IOException {
final ShardId shardId = replica.shardId();
SourceToParse sourceToParse =
SourceToParse.source(SourceToParse.Origin.REPLICA, shardId.getIndexName(), request.type(), request.id(), request.source(),
request.getContentType()).routing(request.routing()).parent(request.parent());
final Engine.Index operation;
final long version = primaryResponse.getVersion();
final VersionType versionType = request.versionType().versionTypeForReplicationAndRecovery();
assert versionType.validateVersionForWrites(version);
final long seqNo = primaryResponse.getSeqNo();
try {
operation = replica.prepareIndexOnReplica(sourceToParse, seqNo, version, versionType, request.getAutoGeneratedTimestamp(), request.isRetry());
} catch (MapperParsingException e) {
return new Engine.IndexResult(e, version, seqNo);
}
Mapping update = operation.parsedDoc().dynamicMappingsUpdate();
if (update != null) {
throw new RetryOnReplicaException(shardId, "Mappings are not available on the replica yet, triggered update: " + update);
}
return replica.index(operation);
}
示例14: testBulkRequestWithRefresh
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
public void testBulkRequestWithRefresh() throws Exception {
BulkRequest bulkRequest = new BulkRequest();
// We force here a "id is missing" validation error
bulkRequest.add(new DeleteRequest("index", "type", null).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
// We force here a "type is missing" validation error
bulkRequest.add(new DeleteRequest("index", null, "id"));
bulkRequest.add(new DeleteRequest("index", "type", "id").setRefreshPolicy(RefreshPolicy.IMMEDIATE));
bulkRequest.add(new UpdateRequest("index", "type", "id").doc("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
bulkRequest.add(new IndexRequest("index", "type", "id").source("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
ActionRequestValidationException validate = bulkRequest.validate();
assertThat(validate, notNullValue());
assertThat(validate.validationErrors(), not(empty()));
assertThat(validate.validationErrors(), contains(
"RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
"id is missing",
"type is missing",
"RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
"RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
"RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead."));
}
示例15: shardIndexOperation
import org.elasticsearch.action.index.IndexRequest; //导入依赖的package包/类
private WriteResult<IndexResponse> shardIndexOperation(BulkShardRequest request, IndexRequest indexRequest, MetaData metaData,
IndexShard indexShard, boolean processed) throws Throwable {
indexShard.checkDiskSpace(fsService);
// validate, if routing is required, that we got routing
MappingMetaData mappingMd = metaData.index(request.index()).mappingOrDefault(indexRequest.type());
if (mappingMd != null && mappingMd.routing().required()) {
if (indexRequest.routing() == null) {
throw new RoutingMissingException(request.index(), indexRequest.type(), indexRequest.id());
}
}
if (!processed) {
indexRequest.process(metaData, mappingMd, allowIdGeneration, request.index());
}
return TransportIndexAction.executeIndexRequestOnPrimary(request, indexRequest, indexShard, mappingUpdatedAction);
}