本文整理汇总了Java中org.elasticsearch.action.index.IndexRequest.OpType类的典型用法代码示例。如果您正苦于以下问题:Java OpType类的具体用法?Java OpType怎么用?Java OpType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpType类属于org.elasticsearch.action.index.IndexRequest包,在下文中一共展示了OpType类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initFromMeta
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
private void initFromMeta() {
index = environmentSubstitute(meta.getIndex());
type = environmentSubstitute(meta.getType());
batchSize = meta.getBatchSizeInt(this);
try {
timeout = Long.parseLong( environmentSubstitute(meta.getTimeOut()));
} catch (NumberFormatException e) {
timeout = null;
}
timeoutUnit = meta.getTimeoutUnit();
isJsonInsert = meta.isJsonInsert();
useOutput = meta.isUseOutput();
stopOnError = meta.isStopOnError();
columnsToJson = meta.getFields();
this.hasFields = columnsToJson.size() > 0;
this.opType = StringUtils.isNotBlank(meta.getIdInField()) && meta.isOverWriteIfSameId() ?
OpType.INDEX :
OpType.CREATE;
}
示例2: save
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
/**
* Slower save, but high protected save.
*/
public void save() {
IndexRequestBuilder create = Elasticsearch.getClient().prepareIndex(ES_INDEX, ES_TYPE, _id).setRefresh(true);
create.setSource(MyDMAM.gson_kit.getGsonSimple().toJson(this));
if (_id == null) {
create.setCreate(true).setOpType(OpType.CREATE).setConsistencyLevel(WriteConsistencyLevel.ALL).setReplicationType(ReplicationType.SYNC);
createAutogeneratedId();
create.setId(_id);
while (create.get().isCreated() == false) {
createAutogeneratedId();
create.setId(_id);
}
} else {
create.get();
}
}
示例3: initFromMeta
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
private void initFromMeta() {
index = environmentSubstitute( meta.getIndex() );
type = environmentSubstitute( meta.getType() );
batchSize = meta.getBatchSizeInt( this );
try {
timeout = Long.parseLong( environmentSubstitute( meta.getTimeOut() ) );
} catch ( NumberFormatException e ) {
timeout = null;
}
timeoutUnit = meta.getTimeoutUnit();
isJsonInsert = meta.isJsonInsert();
useOutput = meta.isUseOutput();
stopOnError = meta.isStopOnError();
columnsToJson = meta.getFieldsMap();
this.hasFields = columnsToJson.size() > 0;
this.opType =
StringUtils.isNotBlank( meta.getIdInField() ) && meta.isOverWriteIfSameId() ? OpType.INDEX : OpType.CREATE;
}
示例4: parse
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
/**
* Mostly just write the data you got from BigQuery into ElasticSearch.
*
* @throws ElasticsearchException
* @throws IOException
* @throws InterruptedException
*/
private void parse(@Nonnull final List<TableRow> rows) throws ElasticsearchException, IOException, InterruptedException {
final int size = rows.size();
int count = 0;
final String timestamp = String.valueOf(System.currentTimeMillis());
int progress = 0;
logger.info("Got {} results from BigQuery database", size);
while (!stopThread && !rows.isEmpty()) {
final TableRow row = rows.remove(0);
final String[] jsonResult = getJson(row);
final String source = jsonResult[0];
final IndexRequestBuilder builder = esClient.prepareIndex(index, type);
if (jsonResult[1] != null) {
builder.setId(jsonResult[1]);
}
try {
builder.setOpType(OpType.CREATE)
.setReplicationType(ReplicationType.ASYNC)
.setOperationThreaded(true)
.setTimestamp(timestamp)
.setSource(source)
.setCreate(create)
.execute()
.actionGet();
count++;
} catch (DocumentAlreadyExistsException daee) {
logger.trace("Document already exists, create flag is {}", daee, create);
}
if (++progress % 100 == 0) {
logger.debug("Processed {} entries ({} percent done)", progress, Math.round((float) progress / (float) size * 100f));
}
}
logger.info("Imported {} entries into ElasticSeach from BigQuery (some duplicates may have been skipped)", count);
return;
}
示例5: doItemUpdate
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
private void doItemUpdate(final Params params,
final RequestHandler.OnErrorListener listener,
final Map<String, Object> requestMap,
final Map<String, Object> paramMap,
final Map<String, Object> itemMap, final String index,
final String type, final String itemIdField,
final String timestampField, final Long itemId,
final OpType opType, final RequestHandlerChain chain) {
itemMap.put(itemIdField, itemId);
itemMap.put(timestampField, new Date());
final OnResponseListener<IndexResponse> responseListener = response -> {
paramMap.put(itemIdField, itemId);
chain.execute(params, listener, requestMap, paramMap);
};
final OnFailureListener failureListener = t -> {
sleep(t);
if (t instanceof DocumentAlreadyExistsException
|| t instanceof EsRejectedExecutionException) {
execute(params, listener, requestMap, paramMap, chain);
} else {
listener.onError(t);
}
};
client.prepareIndex(index, type, itemId.toString()).setSource(itemMap)
.setRefresh(true).setOpType(opType)
.execute(on(responseListener, failureListener));
}
示例6: doUserUpdate
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
private void doUserUpdate(final Params params,
final RequestHandler.OnErrorListener listener,
final Map<String, Object> requestMap,
final Map<String, Object> paramMap,
final Map<String, Object> userMap, final String index,
final String type, final String userIdField,
final String timestampField, final Long userId,
final OpType opType, final RequestHandlerChain chain) {
userMap.put(userIdField, userId);
userMap.put(timestampField, new Date());
final OnResponseListener<IndexResponse> responseListener = response -> {
paramMap.put(userIdField, userId);
chain.execute(params, listener, requestMap, paramMap);
};
final OnFailureListener failureListener = t -> {
if (t instanceof DocumentAlreadyExistsException
|| t instanceof EsRejectedExecutionException) {
sleep(t);
execute(params, listener, requestMap, paramMap, chain);
} else {
listener.onError(t);
}
};
client.prepareIndex(index, type, userId.toString()).setSource(userMap)
.setRefresh(true).setOpType(opType)
.execute(on(responseListener, failureListener));
}
示例7: execute
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
@Override
public void execute(Tuple tuple) {
try {
String index = mapper.getIndex(tuple);
String type = mapper.getType(tuple);
String id = mapper.getId(tuple);
String source = mapper.getSource(tuple);
OpType opType = mapper.getOpType();
client.prepareIndex(index, type).setId(id).setSource(source)
.setOpType(opType).execute();
collector.ack(tuple);
} catch (Exception e) {
collector.fail(tuple);
}
}
示例8: doItemCreation
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
private void doItemCreation(final Params params,
final RequestHandler.OnErrorListener listener,
final Map<String, Object> requestMap,
final Map<String, Object> paramMap,
final Map<String, Object> itemMap, final String index,
final String type, final String itemIdField,
final String timestampField, final RequestHandlerChain chain) {
final OnResponseListener<SearchResponse> responseListener = response -> {
validateRespose(response);
Number currentId = null;
final SearchHits hits = response.getHits();
if (hits.getTotalHits() != 0) {
final SearchHit[] searchHits = hits.getHits();
final SearchHitField field = searchHits[0].getFields().get(
itemIdField);
if (field != null) {
currentId = field.getValue();
}
}
final Long itemId;
if (currentId == null) {
itemId = Long.valueOf(1);
} else {
itemId = Long.valueOf(currentId.longValue() + 1);
}
doItemUpdate(params, listener, requestMap, paramMap, itemMap,
index, type, itemIdField, timestampField, itemId,
OpType.CREATE, chain);
};
final OnFailureListener failureListener = t -> {
final List<Throwable> errorList = getErrorList(paramMap);
if (errorList.size() >= maxRetryCount) {
listener.onError(t);
} else {
sleep(t);
errorList.add(t);
doItemIndexExists(params, listener, requestMap, paramMap,
chain);
}
};
client.prepareSearch(index).setTypes(type)
.setQuery(QueryBuilders.matchAllQuery()).addField(itemIdField)
.addSort(itemIdField, SortOrder.DESC).setSize(1)
.execute(on(responseListener, failureListener));
}
示例9: doUserCreation
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
private void doUserCreation(final Params params,
final RequestHandler.OnErrorListener listener,
final Map<String, Object> requestMap,
final Map<String, Object> paramMap,
final Map<String, Object> userMap, final String index,
final String type, final String userIdField,
final String timestampField, final RequestHandlerChain chain) {
final OnResponseListener<SearchResponse> responseListener = response -> {
validateRespose(response);
Number currentId = null;
final SearchHits hits = response.getHits();
if (hits.getTotalHits() != 0) {
final SearchHit[] searchHits = hits.getHits();
final SearchHitField field = searchHits[0].getFields().get(
userIdField);
if (field != null) {
currentId = field.getValue();
}
}
final Long userId;
if (currentId == null) {
userId = Long.valueOf(1);
} else {
userId = Long.valueOf(currentId.longValue() + 1);
}
doUserUpdate(params, listener, requestMap, paramMap, userMap,
index, type, userIdField, timestampField, userId,
OpType.CREATE, chain);
};
final OnFailureListener failureListener = t -> {
final List<Throwable> errorList = getErrorList(paramMap);
if (errorList.size() >= maxRetryCount) {
listener.onError(t);
} else {
sleep(t);
errorList.add(t);
doUserIndexExists(params, listener, requestMap, paramMap,
chain);
}
};
client.prepareSearch(index).setTypes(type)
.setQuery(QueryBuilders.matchAllQuery()).addField(userIdField)
.addSort(userIdField, SortOrder.DESC).setSize(1)
.execute(on(responseListener, failureListener));
}
示例10: getOpType
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
@Override
public OpType getOpType() {
return OpType.INDEX;
}
示例11: getOpType
import org.elasticsearch.action.index.IndexRequest.OpType; //导入依赖的package包/类
public OpType getOpType();