use of org.elasticsearch.action.index.IndexResponse in project storm-elastic-search by hmsonline.
the class ElasticSearchBolt method execute.
@Override
public void execute(Tuple tuple) {
String id = null;
String indexName = null;
String type = null;
String document = null;
try {
id = this.tupleMapper.mapToId(tuple);
indexName = this.tupleMapper.mapToIndex(tuple);
type = this.tupleMapper.mapToType(tuple);
document = this.tupleMapper.mapToDocument(tuple);
byte[] byteBuffer = document.getBytes();
IndexResponse response = this.client.prepareIndex(indexName, type, id).setSource(byteBuffer).execute().actionGet();
LOG.debug("Indexed Document[ " + id + "], Type[" + type + "], Index[" + indexName + "], Version [" + response.getVersion() + "]");
collector.ack(tuple);
} catch (Exception e) {
LOG.error("Unable to index Document[ " + id + "], Type[" + type + "], Index[" + indexName + "]", e);
collector.ack(tuple);
}
}
use of org.elasticsearch.action.index.IndexResponse in project graylog2-server by Graylog2.
the class CountsTest method totalReturnsNumberOfMessages.
@Test
public void totalReturnsNumberOfMessages() throws Exception {
final int count1 = 10;
final int count2 = 5;
for (int i = 0; i < count1; i++) {
final IndexResponse indexResponse = client.prepareIndex().setIndex(INDEX_NAME_1).setRefresh(true).setType("test").setSource("foo", "bar", "counter", i).execute().get();
assumeTrue(indexResponse.isCreated());
}
for (int i = 0; i < count2; i++) {
final IndexResponse indexResponse = client.prepareIndex().setIndex(INDEX_NAME_2).setRefresh(true).setType("test").setSource("foo", "bar", "counter", i).execute().get();
assumeTrue(indexResponse.isCreated());
}
assertThat(counts.total()).isEqualTo(count1 + count2);
assertThat(counts.total(indexSet1)).isEqualTo(count1);
assertThat(counts.total(indexSet2)).isEqualTo(count2);
}
use of org.elasticsearch.action.index.IndexResponse in project sonarqube by SonarSource.
the class ProxyIndexRequestBuilderTest method trace_logs.
@Test
public void trace_logs() {
logTester.setLevel(LoggerLevel.TRACE);
IndexResponse response = esTester.client().prepareIndex(FakeIndexDefinition.INDEX_TYPE_FAKE).setSource(FakeIndexDefinition.newDoc(42).getFields()).get();
assertThat(response.isCreated()).isTrue();
assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
use of org.elasticsearch.action.index.IndexResponse in project syncope by apache.
the class ElasticsearchReindex method doExecute.
@Override
protected String doExecute(final boolean dryRun) throws JobExecutionException {
if (!dryRun) {
try {
LOG.debug("Start rebuild index {}", AuthContextUtils.getDomain().toLowerCase());
IndicesExistsResponse existsIndexResponse = client.admin().indices().exists(new IndicesExistsRequest(AuthContextUtils.getDomain().toLowerCase())).get();
if (existsIndexResponse.isExists()) {
DeleteIndexResponse deleteIndexResponse = client.admin().indices().delete(new DeleteIndexRequest(AuthContextUtils.getDomain().toLowerCase())).get();
LOG.debug("Successfully removed {}: {}", AuthContextUtils.getDomain().toLowerCase(), deleteIndexResponse);
}
XContentBuilder settings = XContentFactory.jsonBuilder().startObject().startObject("analysis").startObject("analyzer").startObject("string_lowercase").field("type", "custom").field("tokenizer", "standard").field("filter").startArray().value("lowercase").endArray().endObject().endObject().endObject().endObject();
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startArray("dynamic_templates").startObject().startObject("strings").field("match_mapping_type", "string").startObject("mapping").field("type", "keyword").field("analyzer", "string_lowercase").endObject().endObject().endObject().endArray().endObject();
CreateIndexResponse createIndexResponse = client.admin().indices().create(new CreateIndexRequest(AuthContextUtils.getDomain().toLowerCase()).settings(settings).mapping(AnyTypeKind.USER.name(), mapping).mapping(AnyTypeKind.GROUP.name(), mapping).mapping(AnyTypeKind.ANY_OBJECT.name(), mapping)).get();
LOG.debug("Successfully created {}: {}", AuthContextUtils.getDomain().toLowerCase(), createIndexResponse);
LOG.debug("Indexing users...");
for (int page = 1; page <= (userDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (User user : userDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexResponse response = client.prepareIndex(AuthContextUtils.getDomain().toLowerCase(), AnyTypeKind.USER.name(), user.getKey()).setSource(elasticsearchUtils.builder(user)).get();
LOG.debug("Index successfully created for {}: {}", user, response);
}
}
LOG.debug("Indexing groups...");
for (int page = 1; page <= (groupDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (Group group : groupDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexResponse response = client.prepareIndex(AuthContextUtils.getDomain().toLowerCase(), AnyTypeKind.GROUP.name(), group.getKey()).setSource(elasticsearchUtils.builder(group)).get();
LOG.debug("Index successfully created for {}: {}", group, response);
}
}
LOG.debug("Indexing any objects...");
for (int page = 1; page <= (anyObjectDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (AnyObject anyObject : anyObjectDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexResponse response = client.prepareIndex(AuthContextUtils.getDomain().toLowerCase(), AnyTypeKind.ANY_OBJECT.name(), anyObject.getKey()).setSource(elasticsearchUtils.builder(anyObject)).get();
LOG.debug("Index successfully created for {}: {}", anyObject, response);
}
}
LOG.debug("Rebuild index {} successfully completed", AuthContextUtils.getDomain().toLowerCase());
} catch (Exception e) {
throw new JobExecutionException("While rebuilding index " + AuthContextUtils.getDomain().toLowerCase(), e);
}
}
return "SUCCESS";
}
use of org.elasticsearch.action.index.IndexResponse in project incubator-skywalking by apache.
the class ApplicationRegisterEsDAO method save.
@Override
public void save(Application application) {
logger.debug("save application register info, application getApplicationId: {}, application code: {}", application.getId(), application.getApplicationCode());
ElasticSearchClient client = getClient();
Map<String, Object> source = new HashMap<>();
source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode());
source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId());
source.put(ApplicationTable.COLUMN_ADDRESS_ID, application.getAddressId());
source.put(ApplicationTable.COLUMN_IS_ADDRESS, application.getIsAddress());
IndexResponse response = client.prepareIndex(ApplicationTable.TABLE, application.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
logger.debug("save application register info, application getApplicationId: {}, application code: {}, status: {}", application.getApplicationId(), application.getApplicationCode(), response.status().name());
}
Aggregations