use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project metron by apache.
the class ElasticsearchDao method update.
@Override
public void update(Document update, Optional<String> index) throws IOException {
String indexPostfix = ElasticsearchUtils.getIndexFormat(accessConfig.getGlobalConfigSupplier().get()).format(new Date());
String sensorType = update.getSensorType();
String indexName = getIndexName(update, index, indexPostfix);
IndexRequest indexRequest = buildIndexRequest(update, sensorType, indexName);
try {
IndexResponse response = client.index(indexRequest).get();
ShardInfo shardInfo = response.getShardInfo();
int failed = shardInfo.getFailed();
if (failed > 0) {
throw new IOException("ElasticsearchDao index failed: " + Arrays.toString(shardInfo.getFailures()));
}
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
}
}
Aggregations