本文整理汇总了Java中org.elasticsearch.action.bulk.BulkRequestBuilder.add方法的典型用法代码示例。如果您正苦于以下问题:Java BulkRequestBuilder.add方法的具体用法?Java BulkRequestBuilder.add怎么用?Java BulkRequestBuilder.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.bulk.BulkRequestBuilder
的用法示例。
在下文中一共展示了BulkRequestBuilder.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unindexAll
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public <P extends ParaObject> void unindexAll(String appid, List<P> objects) {
if (StringUtils.isBlank(appid) || objects == null || objects.isEmpty()) {
return;
}
BulkRequestBuilder brb = client().prepareBulk();
for (ParaObject po : objects) {
brb.add(client().prepareDelete(getIndexName(appid), getType(), po.getId()));
}
if (brb.numberOfActions() > 0) {
ActionListener<BulkResponse> responseHandler = ElasticSearchUtils.getBulkIndexResponseHandler();
if (isAsyncEnabled()) {
brb.execute(responseHandler);
} else {
responseHandler.onResponse(brb.execute().actionGet());
}
}
logger.debug("Search.unindexAll() {}", objects.size());
}
示例2: bulkDelete
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public String bulkDelete(String index, String type, String... ids) {
try {
if(client==null){
init();
}
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (String id : ids) {
bulkRequest.add(client.prepareDelete(index, type, id));
}
BulkResponse result = bulkRequest.execute().get();
return result.toString();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例3: indexAll
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public <P extends ParaObject> void indexAll(String appid, List<P> objects) {
if (StringUtils.isBlank(appid) || objects == null || objects.isEmpty()) {
return;
}
BulkRequestBuilder brb = client().prepareBulk();
for (ParaObject po : objects) {
brb.add(client().prepareIndex(getIndexName(appid), getType(), po.getId()).
setSource(ElasticSearchUtils.getSourceFromParaObject(po)));
}
if (brb.numberOfActions() > 0) {
ActionListener<BulkResponse> responseHandler = ElasticSearchUtils.getBulkIndexResponseHandler();
if (isAsyncEnabled()) {
brb.execute(responseHandler);
} else {
responseHandler.onResponse(brb.execute().actionGet());
}
}
logger.debug("Search.indexAll() {}", objects.size());
}
示例4: testBulk
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
public void testBulk() {
// Index by bulk with RefreshPolicy.WAIT_UNTIL
BulkRequestBuilder bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
bulk.add(client().prepareIndex("test", "test", "1").setSource("foo", "bar"));
assertBulkSuccess(bulk.get());
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get(), "1");
// Update by bulk with RefreshPolicy.WAIT_UNTIL
bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
bulk.add(client().prepareUpdate("test", "test", "1").setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "baz"));
assertBulkSuccess(bulk.get());
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "baz")).get(), "1");
// Delete by bulk with RefreshPolicy.WAIT_UNTIL
bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
bulk.add(client().prepareDelete("test", "test", "1"));
assertBulkSuccess(bulk.get());
assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get());
// Update makes a noop
bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
bulk.add(client().prepareDelete("test", "test", "1"));
assertBulkSuccess(bulk.get());
}
示例5: bulkUpsert
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
public String bulkUpsert(String index,String type,List<Object> jsons){
try {
if(client==null){
init();
}
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (Object json : jsons) {
JSONObject obj = JSON.parseObject(JSON.toJSONString(json));
String id = UUIDs.base64UUID();
if(obj.containsKey("id")){
id = obj.getString("id");
obj.remove("id");
bulkRequest.add(client.prepareUpdate(index, type, id).setDoc(obj.toJSONString(),XContentType.JSON));
}else{
bulkRequest.add(client.prepareIndex(index, type, id).setSource(obj.toJSONString(),XContentType.JSON));
}
}
BulkResponse result = bulkRequest.execute().get();
return result.toString();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例6: doJob
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public void doJob(EventLog log, LogDto logDto, BulkRequestBuilder bulkRequest) {
// 进行索引(for kibana),包含api调用、第三方调用、中间件调用
if (this.getTypes().indexOf(log.getEventType()) != -1 && (log.getStatus().equals(EventLog.MONITOR_STATUS_FAILED) || log.getStatus().equals(EventLog.MONITOR_STATUS_SUCCESS))) {
try {
bulkRequest.add(transportClient.prepareIndex(this.esProperties.getIndex(), this.esProperties.getDoc())
.setSource(this.buildXContentBuilder(log, logDto)));
} catch (IOException e) {
LOGGER.error("构造一条es入库数据失败, {]", logDto);
}
}
// 进行后续的处理
if (null != this.getNextJob()) {
this.getNextJob().doJob(log, logDto, bulkRequest);
}
}
示例7: updateWithBulkTest
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Test
public void updateWithBulkTest() throws IOException {
BulkRequestBuilder request = client.prepareBulk();
request.add(client.prepareUpdate(INDEX_NAME, TYPE_NAME, "AVQcXWKy50MnK8WFflRS")
.setDoc(jsonBuilder()
.startObject()
.field("name", "testUpdateBulk")
.endObject()
)
);
request.add(client.prepareUpdate(INDEX_NAME, TYPE_NAME, "AVQcU5cD50MnK8WFflRQ")
.setDoc(jsonBuilder()
.startObject()
.field("name", "testUpdateBulk2")
.endObject()
)
);
BulkResponse response = request.execute().actionGet();
Assert.assertFalse(response.hasFailures());
}
示例8: execute
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
/**
* Executes the list with requests as a bulk with maximum number of requests per bulk
* @param requests
* @param maxRequestsPerBulk
* @return
* @throws SQLException
*/
private int execute(List<?> requests, int maxRequestsPerBulk) throws SQLException{
int result = 0;
BulkRequestBuilder bulkReq = client.prepareBulk();
for(Object req : requests){
if(req instanceof IndexRequest) bulkReq.add((IndexRequest)req);
else if(req instanceof UpdateRequest) bulkReq.add((UpdateRequest)req);
else if(req instanceof DeleteRequest) bulkReq.add((DeleteRequest)req);
else if(req instanceof IndexRequestBuilder) bulkReq.add((IndexRequestBuilder)req);
else if(req instanceof UpdateRequestBuilder) bulkReq.add((UpdateRequestBuilder)req);
else if(req instanceof DeleteRequestBuilder) bulkReq.add((DeleteRequestBuilder)req);
else throw new SQLException("Type "+req.getClass()+" cannot be added to a bulk request");
if(bulkReq.numberOfActions() > maxRequestsPerBulk){
result += bulkReq.get().getItems().length;
bulkReq = client.prepareBulk();
}
}
if(bulkReq.numberOfActions() > 0){
result += bulkReq.get().getItems().length;
}
return result;
}
示例9: writeDependencyLinks
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@VisibleForTesting void writeDependencyLinks(List<DependencyLink> links, long timestampMillis) {
long midnight = Util.midnightUTC(timestampMillis);
TransportClient client = ((NativeClient) storage.client()).client;
BulkRequestBuilder request = client.prepareBulk();
for (DependencyLink link : links) {
request.add(client.prepareIndex(
storage.indexNameFormatter.indexNameForTimestamp(midnight),
ElasticsearchConstants.DEPENDENCY_LINK)
.setId(link.parent + "|" + link.child) // Unique constraint
.setSource(
"parent", link.parent,
"child", link.child,
"callCount", link.callCount));
}
request.execute().actionGet();
client.admin().indices().flush(new FlushRequest()).actionGet();
}
示例10: insert
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public void insert(List<BucketOwner> bucketOwners, Date collectionTime) {
if (bucketOwners != null && !bucketOwners.isEmpty()) {
BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
// Generate JSON for object buckets info
for (BucketOwner bucketOwner : bucketOwners) {
XContentBuilder objectBucketBuilder = toJsonFormat(bucketOwner, collectionTime);
IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(bucketownerIndexDayName)
.setType(BUCKET_OWNER_INDEX_TYPE).setSource(objectBucketBuilder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
LOGGER.info("Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in ElasticSearch"
+ "index: " + bucketownerIndexDayName + " index type: " + BUCKET_OWNER_INDEX_TYPE);
if (bulkResponse.hasFailures()) {
LOGGER.error("Failures occured while items in ElasticSearch " + "index: " + bucketownerIndexDayName
+ " index type: " + BUCKET_OWNER_INDEX_TYPE);
}
}
}
示例11: deleteAllIds
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public List<String> deleteAllIds(final Collection<String> ids) {
if (ids.isEmpty()) {
return ImmutableList.of();
}
final BulkRequestBuilder bulk = client
.prepareBulk()
.setRefreshPolicy(policy.get());
for (final String id : ids) {
bulk.add(client.prepareDelete(index, type, id));
}
final BulkResponse response = bulk.execute().actionGet();
final ImmutableList.Builder<String> builder = ImmutableList.builder();
for (final BulkItemResponse item : response.getItems()) {
builder.add(item.getId());
}
return builder.build();
}
示例12: before
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Before
public void before() throws IOException {
if(!client.admin().indices().prepareExists(INDEX).execute().actionGet().isExists()) {
client.admin().indices().prepareCreate(INDEX).execute().actionGet();
}
final JsonSerializer<Person> serializer = mapper.serializer(Person.class);
final BulkRequestBuilder bulk = client.prepareBulk();
for (int i = 0; i < SIZE; i++) {
final String name = UUID.randomUUID().toString();
final IndexRequest request = new IndexRequest(INDEX, TYPE);
request.source(serializer.apply(Person.builder().id("").firstname(name).lastname(name).build()), JSON);
bulk.add(request);
}
client.bulk(bulk.request()).actionGet();
flush(INDEX);
}
示例13: before
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Before
public void before() throws IOException {
if(!client.admin().indices().prepareExists(INDEX).execute().actionGet().isExists()) {
client.admin().indices().prepareCreate(INDEX).execute().actionGet();
}
final BulkRequestBuilder bulk = client.prepareBulk();
final JsonSerializer<Person> serializer = mapper.serializer(Person.class);
for (int i = 0; i < SIZE; i++) {
final String name = UUID.randomUUID().toString();
final IndexRequest request = new IndexRequest(INDEX, TYPE);
request.source(serializer.apply(Person.builder().id("").firstname(name).lastname(name).build()), JSON);
bulk.add(request);
}
client.bulk(bulk.request()).actionGet();
flush(INDEX);
}
示例14: bulkDelete
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public void bulkDelete(BulkDeleteRequest request) {
if (request.ids == null || request.ids.isEmpty()) throw Exceptions.error("request.ids must not be empty");
StopWatch watch = new StopWatch();
String index = request.index == null ? this.index : request.index;
BulkRequestBuilder builder = client().prepareBulk();
for (String id : request.ids) {
builder.add(client().prepareDelete(index, type, id));
}
long esTookTime = 0;
try {
BulkResponse response = builder.get();
esTookTime = response.getTook().nanos();
if (response.hasFailures()) throw new SearchException(response.buildFailureMessage());
} catch (ElasticsearchException e) {
throw new SearchException(e); // due to elastic search uses async executor to run, we have to wrap the exception to retain the original place caused the exception
} finally {
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("elasticsearch", elapsedTime, 0, request.ids.size());
logger.debug("bulkDelete, index={}, type={}, size={}, esTookTime={}, elapsedTime={}", index, type, request.ids.size(), esTookTime, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
示例15: beforeTest
import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Before
public void beforeTest() throws Exception{
jCas = JCasSingleton.getJCasInstance();
try{
//Find all documents in index and delete the documents
BulkRequestBuilder brb = client.prepareBulk();
SearchHits results = client.search(new SearchRequest()).actionGet().getHits();
for(SearchHit sh : results){
brb.add(client.prepareDelete("baleen_index", "baleen_output", sh.getId()).request());
}
if(brb.numberOfActions() > 0)
brb.get();
}catch(IndexNotFoundException infe){
//Index doesn't exist - ignore
}
}