use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexResponse in project elasticsearch by elastic.
the class ListenerActionIT method testThreadedListeners.
public void testThreadedListeners() throws Throwable {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> failure = new AtomicReference<>();
final AtomicReference<String> threadName = new AtomicReference<>();
Client client = client();
IndexRequest request = new IndexRequest("test", "type", "1");
if (randomBoolean()) {
// set the source, without it, we will have a verification failure
request.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
}
client.index(request, new ActionListener<IndexResponse>() {
@Override
public void onResponse(IndexResponse indexResponse) {
threadName.set(Thread.currentThread().getName());
latch.countDown();
}
@Override
public void onFailure(Exception e) {
threadName.set(Thread.currentThread().getName());
failure.set(e);
latch.countDown();
}
});
latch.await();
boolean shouldBeThreaded = TransportClient.CLIENT_TYPE.equals(Client.CLIENT_TYPE_SETTING_S.get(client.settings()));
if (shouldBeThreaded) {
assertTrue(threadName.get().contains("listener"));
} else {
assertFalse(threadName.get().contains("listener"));
}
}
use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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