use of org.elasticsearch.action.index.IndexRequest in project titan by thinkaurelius.
the class ElasticSearchIndex method restore.
public void restore(Map<String, Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException {
BulkRequestBuilder bulk = client.prepareBulk();
int requests = 0;
try {
for (Map.Entry<String, Map<String, List<IndexEntry>>> stores : documents.entrySet()) {
String store = stores.getKey();
for (Map.Entry<String, List<IndexEntry>> entry : stores.getValue().entrySet()) {
String docID = entry.getKey();
List<IndexEntry> content = entry.getValue();
if (content == null || content.size() == 0) {
// delete
if (log.isTraceEnabled())
log.trace("Deleting entire document {}", docID);
bulk.add(new DeleteRequest(indexName, store, docID));
requests++;
} else {
// Add
if (log.isTraceEnabled())
log.trace("Adding entire document {}", docID);
bulk.add(new IndexRequest(indexName, store, docID).source(getNewDocument(content, informations.get(store), IndexMutation.determineTTL(content))));
requests++;
}
}
}
if (requests > 0)
bulk.execute().actionGet();
} catch (Exception e) {
throw convert(e);
}
}
use of org.elasticsearch.action.index.IndexRequest in project camel by apache.
the class ElasticsearchBulkTest method bulkRequestBody.
@Test
public void bulkRequestBody() throws Exception {
String prefix = createPrefix();
// given
BulkRequest request = new BulkRequest();
request.add(new IndexRequest(prefix + "foo", prefix + "bar", prefix + "baz").source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"));
// when
BulkResponse response = template.requestBody("direct:bulk", request, BulkResponse.class);
// then
assertThat(response, notNullValue());
assertEquals(prefix + "baz", response.getItems()[0].getId());
}
use of org.elasticsearch.action.index.IndexRequest in project camel by apache.
the class ElasticsearchGetSearchDeleteExistsUpdateTest method deleteRequestBody.
@Test
public void deleteRequestBody() throws Exception {
String prefix = createPrefix();
// given
DeleteRequest request = new DeleteRequest(prefix + "foo").type(prefix + "bar");
// when
String documentId = template.requestBody("direct:index", new IndexRequest("" + prefix + "foo", "" + prefix + "bar", "" + prefix + "testId").source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"), String.class);
DeleteResponse response = template.requestBody("direct:delete", request.id(documentId), DeleteResponse.class);
// then
assertThat(response, notNullValue());
assertThat(documentId, equalTo(response.getId()));
}
use of org.elasticsearch.action.index.IndexRequest in project camel by apache.
the class ElasticsearchGetSearchDeleteExistsUpdateTest method getRequestBody.
@Test
public void getRequestBody() throws Exception {
String prefix = createPrefix();
// given
GetRequest request = new GetRequest(prefix + "foo").type(prefix + "bar");
// when
String documentId = template.requestBody("direct:index", new IndexRequest(prefix + "foo", prefix + "bar", prefix + "testId").source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"), String.class);
GetResponse response = template.requestBody("direct:get", request.id(documentId), GetResponse.class);
// then
assertThat(response, notNullValue());
assertThat(prefix + "hello", equalTo(response.getSourceAsMap().get(prefix + "content")));
}
use of org.elasticsearch.action.index.IndexRequest in project metron by apache.
the class ElasticsearchDao method buildIndexRequest.
protected IndexRequest buildIndexRequest(Document update, String sensorType, String indexName) {
String type = sensorType + "_doc";
Object ts = update.getTimestamp();
IndexRequest indexRequest = new IndexRequest(indexName, type, update.getGuid()).source(update.getDocument());
if (ts != null) {
indexRequest = indexRequest.timestamp(ts.toString());
}
return indexRequest;
}
Aggregations