use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.
the class IndexStatsIT method testClearAllCaches.
public void testClearAllCaches() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_replicas", 0).put("index.number_of_shards", 2)).addMapping("type", "field", "type=text,fielddata=true").get());
ensureGreen();
client().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
client().prepareIndex("test", "type", "1").setSource("field", "value1").execute().actionGet();
client().prepareIndex("test", "type", "2").setSource("field", "value2").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
NodesStatsResponse nodesStats = client().admin().cluster().prepareNodesStats("data:true").setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes().get(0).getIndices().getFieldData().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0L));
assertThat(nodesStats.getNodes().get(0).getIndices().getQueryCache().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getQueryCache().getMemorySizeInBytes(), equalTo(0L));
IndicesStatsResponse indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).setQueryCache(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), equalTo(0L));
assertThat(indicesStats.getTotal().getQueryCache().getMemorySizeInBytes(), equalTo(0L));
// sort to load it to field data and filter to load filter cache
client().prepareSearch().setPostFilter(QueryBuilders.termQuery("field", "value1")).addSort("field", SortOrder.ASC).execute().actionGet();
client().prepareSearch().setPostFilter(QueryBuilders.termQuery("field", "value2")).addSort("field", SortOrder.ASC).execute().actionGet();
nodesStats = client().admin().cluster().prepareNodesStats("data:true").setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes().get(0).getIndices().getFieldData().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
assertThat(nodesStats.getNodes().get(0).getIndices().getQueryCache().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getQueryCache().getMemorySizeInBytes(), greaterThan(0L));
indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).setQueryCache(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
assertThat(indicesStats.getTotal().getQueryCache().getMemorySizeInBytes(), greaterThan(0L));
client().admin().indices().prepareClearCache().execute().actionGet();
// Make sure the filter cache entries have been removed...
Thread.sleep(100);
nodesStats = client().admin().cluster().prepareNodesStats("data:true").setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes().get(0).getIndices().getFieldData().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0L));
assertThat(nodesStats.getNodes().get(0).getIndices().getQueryCache().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getQueryCache().getMemorySizeInBytes(), equalTo(0L));
indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).setQueryCache(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), equalTo(0L));
assertThat(indicesStats.getTotal().getQueryCache().getMemorySizeInBytes(), equalTo(0L));
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.
the class IndexStatsIT method testSegmentsStats.
public void testSegmentsStats() {
assertAcked(prepareCreate("test1", 2, settingsBuilder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1))));
ensureGreen();
NumShards test1 = getNumShards("test1");
for (int i = 0; i < 100; i++) {
index("test1", "type1", Integer.toString(i), "field", "value");
index("test1", "type2", Integer.toString(i), "field", "value");
}
IndicesStatsResponse stats = client().admin().indices().prepareStats().setSegments(true).get();
assertThat(stats.getTotal().getSegments().getIndexWriterMemoryInBytes(), greaterThan(0L));
assertThat(stats.getTotal().getSegments().getVersionMapMemoryInBytes(), greaterThan(0L));
client().admin().indices().prepareFlush().get();
client().admin().indices().prepareForceMerge().setMaxNumSegments(1).execute().actionGet();
stats = client().admin().indices().prepareStats().setSegments(true).get();
assertThat(stats.getTotal().getSegments(), notNullValue());
assertThat(stats.getTotal().getSegments().getCount(), equalTo((long) test1.totalNumShards));
assertThat(stats.getTotal().getSegments().getMemoryInBytes(), greaterThan(0L));
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.
the class IndexStatsIT method testMultiIndex.
public void testMultiIndex() throws Exception {
createIndex("test1");
createIndex("test2");
ensureGreen();
client().prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet();
refresh();
int numShards1 = getNumShards("test1").totalNumShards;
int numShards2 = getNumShards("test2").totalNumShards;
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
IndicesStatsResponse stats = builder.execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("_all").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("_all").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("*").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("test1").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1));
stats = builder.setIndices("test1", "test2").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("*2").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards2));
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.
the class SearchWithRejectionsIT method testOpenContextsAfterRejections.
public void testOpenContextsAfterRejections() throws InterruptedException {
createIndex("test");
ensureGreen("test");
final int docs = scaledRandomIntBetween(20, 50);
for (int i = 0; i < docs; i++) {
client().prepareIndex("test", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
}
IndicesStatsResponse indicesStats = client().admin().indices().prepareStats().execute().actionGet();
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo(0L));
refresh();
int numSearches = 10;
Future<SearchResponse>[] responses = new Future[numSearches];
SearchType searchType = randomFrom(SearchType.DEFAULT, SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH);
logger.info("search type is {}", searchType);
for (int i = 0; i < numSearches; i++) {
responses[i] = client().prepareSearch().setQuery(matchAllQuery()).setSearchType(searchType).execute();
}
for (int i = 0; i < numSearches; i++) {
try {
responses[i].get();
} catch (Exception t) {
}
}
awaitBusy(() -> client().admin().indices().prepareStats().execute().actionGet().getTotal().getSearch().getOpenContexts() == 0, 1, TimeUnit.SECONDS);
indicesStats = client().admin().indices().prepareStats().execute().actionGet();
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo(0L));
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project graylog2-server by Graylog2.
the class Indices method indexStats.
@Nullable
public IndexStats indexStats(final String indexName) {
final IndicesStatsRequest request = c.admin().indices().prepareStats(indexName).request();
final IndicesStatsResponse response = c.admin().indices().stats(request).actionGet();
return response.getIndex(indexName);
}
Aggregations