@Override public String index() { return this.searchHit.index(); }
void onBulkFailure(String scrollId, SearchHit[] docs, Throwable failure) { try { logger.trace("execution of scroll request failed: {}", failure.getMessage()); for (SearchHit doc : docs) { IndexDeleteByQueryResponse indexCounter = results.get(doc.index()); if (indexCounter == null) { indexCounter = new IndexDeleteByQueryResponse(doc.index()); } indexCounter.incrementFound(); indexCounter.incrementFailed(); results.put(doc.getIndex(), indexCounter); } logger.trace("scrolling document terminated due to scroll request failure [{}]", scrollId); finishHim(scrollId, hasTimedOut(), failure); } catch (Throwable t) { logger.error("unable to process bulk failure", t); finishHim(scrollId, false, t); } }
private void deleteIndexType(final String fromIndex, final String fromType) { final SearchRequestBuilder builder = client.prepareSearch(fromIndex).setTypes(fromType).setScroll("1m"); SearchResponse searchResponse = builder.get(); SearchHit[] hits = searchResponse.getHits().getHits(); for (SearchHit hit : hits) client.prepareDelete(hit.index(), hit.type(), hit.id()).get(); while (hits.length != 0) { searchResponse = client.prepareSearchScroll(searchResponse.getScrollId()).setScroll("1m").get(); hits = searchResponse.getHits().getHits(); for (SearchHit hit : hits) client.prepareDelete(hit.index(), hit.type(), hit.id()).get(); } }
@Override public GetResponse getDelegatedFromInstigator(final SearchResponse searchResponse) { if (searchResponse.getHits().getTotalHits() <= 0) { return new GetResponse(new GetResult(request.index(), request.type(), request.id(), request.version(), false, null, null)); } else if (searchResponse.getHits().getTotalHits() > 1) { throw new RuntimeException("cannot happen"); } else { final SearchHit sh = searchResponse.getHits().getHits()[0]; return new GetResponse(new GetResult(sh.index(), sh.type(), sh.id(), sh.version(), true, sh.getSourceRef(), null)); } } });
void dumpSave(Client client, Builder builder) throws IOException { TimeValue scrollDuration = TimeValue.timeValueSeconds(30); SearchResponse searchResponse = client.prepareSearch(builder.indices()) .setTypes(builder.types()).setSearchType(SearchType.SCAN) .setQuery(builder.query()).setSize(100).setScroll(scrollDuration).execute().actionGet(); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(builder.path(), true), builder.charset()); int i = 0; try { while (true) { searchResponse = client.prepareSearchScroll(searchResponse.getScrollId()) .setScroll(scrollDuration).execute().actionGet(); if (searchResponse.getHits().hits().length == 0) { break; } for (SearchHit hit : searchResponse.getHits()) { Document document = Document.fromSource(hit.sourceAsString(), hit.index(), hit.type(), hit.id()); writer.write(document.getDump()); i++; writer.write('\n'); } } } finally { writer.close(); console.println("Saved " + i + " documents to " + builder.path()); } }
for (SearchHit hit : searchHits.hits()) { ImmutableMap.Builder<String, Object> hitProperties = ImmutableMap.builder(); hitProperties.put("_index", hit.index()); hitProperties.put("_type", hit.type()); hitProperties.put("_id", hit.id());
for (SearchHit hit : searchHits.hits()) { ImmutableMap.Builder<String, Object> hitProperties = ImmutableMap.builder(); hitProperties.put("_index", hit.index()); hitProperties.put("_type", hit.type()); hitProperties.put("_id", hit.id());
@Override public GetResponse getDelegatedFromInstigator(final MultiSearchResponse searchResponse) { if (searchResponse.getResponses() == null || searchResponse.getResponses().length <= 0) { final Item item = request.getItems().get(0); return new GetResponse(new GetResult(item.index(), item.type(), item.id(), item.version(), false, null, null)); } else if (searchResponse.getResponses().length > 1) { throw new RuntimeException("cannot happen"); } else { final org.elasticsearch.action.search.MultiSearchResponse.Item item = searchResponse.getResponses()[0]; final SearchHit sh = item.getResponse().getHits().getHits()[0]; return new GetResponse(new GetResult(sh.index(), sh.type(), sh.id(), sh.version(), true, sh.getSourceRef(), null)); } } });
@Override protected IndexRequest buildIndexRequest(SearchHit doc) { IndexRequest index = new IndexRequest(mainRequest); index.index(doc.index()); index.type(doc.type()); index.id(doc.id()); index.source(doc.sourceRef()); index.versionType(VersionType.INTERNAL); index.version(doc.version()); return index; }
doc.setField("_index", hit.index()); doc.setField("_type", hit.type()); doc.setField("_id", hit.id());
@Override protected IndexRequest buildIndexRequest(SearchHit doc) { IndexRequest index = new IndexRequest(mainRequest); index.index(doc.index()); index.type(doc.type()); index.id(doc.id()); index.source(doc.sourceRef()); index.versionType(VersionType.INTERNAL); index.version(doc.version()); return index; }
bulkRequestBuilder.add(client.prepareDelete(hit.index(), hit.type(), hit.id()));
bulkRequestBuilder.add(client.prepareDelete(hit.index(), hit.type(), hit.id()));
bulkRequestBuilder.add(client.prepareDelete(hit.index(), hit.type(), hit.id()));
DeleteRequest delete = new DeleteRequest().index(hit.index()) .type(hit.type()) .id(hit.id());
DeleteRequest delete = new DeleteRequest().index(hit.index()) .type(hit.type()) .id(hit.id());
DeleteRequest delete = new DeleteRequest(request).index(doc.index()).type(doc.type()).id(doc.id()).version(doc.version()); SearchHitField routing = doc.field("_routing"); if (routing != null) {