in server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java [632:892]
Table buildTable(
final RestRequest request,
final Map<String, Settings> indicesSettings,
final Map<String, ClusterIndexHealth> indicesHealths,
final Map<String, IndexStats> indicesStats,
final Map<String, IndexMetadata> indicesMetadatas
) {
final String healthParam = request.param("health");
final Table table = getTableWithHeader(request);
indicesSettings.forEach((indexName, settings) -> {
if (indicesMetadatas.containsKey(indexName) == false) {
// the index exists in the Get Indices response but is not present in the cluster state:
// it is likely that the index was deleted in the meanwhile, so we ignore it.
return;
}
final IndexMetadata indexMetadata = indicesMetadatas.get(indexName);
final IndexMetadata.State indexState = indexMetadata.getState();
final IndexStats indexStats = indicesStats.get(indexName);
final boolean searchThrottled = IndexSettings.INDEX_SEARCH_THROTTLED.get(settings);
final String health;
final ClusterIndexHealth indexHealth = indicesHealths.get(indexName);
if (indexHealth != null) {
health = indexHealth.getStatus().toString().toLowerCase(Locale.ROOT);
} else if (indexStats != null) {
health = "red*";
} else {
health = "";
}
if (healthParam != null) {
final ClusterHealthStatus healthStatusFilter = ClusterHealthStatus.fromString(healthParam);
boolean skip;
if (indexHealth != null) {
// index health is known but does not match the one requested
skip = indexHealth.getStatus() != healthStatusFilter;
} else {
// index health is unknown, skip if we don't explicitly request RED health
skip = ClusterHealthStatus.RED != healthStatusFilter;
}
if (skip) {
return;
}
}
final CommonStats primaryStats;
final CommonStats totalStats;
if (indexStats == null || indexState == IndexMetadata.State.CLOSE) {
// TODO: expose docs stats for replicated closed indices
primaryStats = new CommonStats();
totalStats = new CommonStats();
} else {
primaryStats = indexStats.getPrimaries();
totalStats = indexStats.getTotal();
}
table.startRow();
table.addCell(health);
table.addCell(indexState.toString().toLowerCase(Locale.ROOT));
table.addCell(indexName);
table.addCell(indexMetadata.getIndexUUID());
table.addCell(indexHealth == null ? null : indexHealth.getNumberOfShards());
table.addCell(indexHealth == null ? null : indexHealth.getNumberOfReplicas());
table.addCell(primaryStats.getDocs() == null ? null : primaryStats.getDocs().getCount());
table.addCell(primaryStats.getDocs() == null ? null : primaryStats.getDocs().getDeleted());
table.addCell(indexMetadata.getCreationDate());
ZonedDateTime creationTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(indexMetadata.getCreationDate()), ZoneOffset.UTC);
table.addCell(STRICT_DATE_TIME_FORMATTER.format(creationTime));
table.addCell(totalStats.getStore() == null ? null : totalStats.getStore().size());
table.addCell(primaryStats.getStore() == null ? null : primaryStats.getStore().size());
table.addCell(totalStats.getCompletion() == null ? null : totalStats.getCompletion().getSize());
table.addCell(primaryStats.getCompletion() == null ? null : primaryStats.getCompletion().getSize());
table.addCell(totalStats.getFieldData() == null ? null : totalStats.getFieldData().getMemorySize());
table.addCell(primaryStats.getFieldData() == null ? null : primaryStats.getFieldData().getMemorySize());
table.addCell(totalStats.getFieldData() == null ? null : totalStats.getFieldData().getEvictions());
table.addCell(primaryStats.getFieldData() == null ? null : primaryStats.getFieldData().getEvictions());
table.addCell(totalStats.getQueryCache() == null ? null : totalStats.getQueryCache().getMemorySize());
table.addCell(primaryStats.getQueryCache() == null ? null : primaryStats.getQueryCache().getMemorySize());
table.addCell(totalStats.getQueryCache() == null ? null : totalStats.getQueryCache().getEvictions());
table.addCell(primaryStats.getQueryCache() == null ? null : primaryStats.getQueryCache().getEvictions());
table.addCell(totalStats.getRequestCache() == null ? null : totalStats.getRequestCache().getMemorySize());
table.addCell(primaryStats.getRequestCache() == null ? null : primaryStats.getRequestCache().getMemorySize());
table.addCell(totalStats.getRequestCache() == null ? null : totalStats.getRequestCache().getEvictions());
table.addCell(primaryStats.getRequestCache() == null ? null : primaryStats.getRequestCache().getEvictions());
table.addCell(totalStats.getRequestCache() == null ? null : totalStats.getRequestCache().getHitCount());
table.addCell(primaryStats.getRequestCache() == null ? null : primaryStats.getRequestCache().getHitCount());
table.addCell(totalStats.getRequestCache() == null ? null : totalStats.getRequestCache().getMissCount());
table.addCell(primaryStats.getRequestCache() == null ? null : primaryStats.getRequestCache().getMissCount());
table.addCell(totalStats.getFlush() == null ? null : totalStats.getFlush().getTotal());
table.addCell(primaryStats.getFlush() == null ? null : primaryStats.getFlush().getTotal());
table.addCell(totalStats.getFlush() == null ? null : totalStats.getFlush().getTotalTime());
table.addCell(primaryStats.getFlush() == null ? null : primaryStats.getFlush().getTotalTime());
table.addCell(totalStats.getGet() == null ? null : totalStats.getGet().current());
table.addCell(primaryStats.getGet() == null ? null : primaryStats.getGet().current());
table.addCell(totalStats.getGet() == null ? null : totalStats.getGet().getTime());
table.addCell(primaryStats.getGet() == null ? null : primaryStats.getGet().getTime());
table.addCell(totalStats.getGet() == null ? null : totalStats.getGet().getCount());
table.addCell(primaryStats.getGet() == null ? null : primaryStats.getGet().getCount());
table.addCell(totalStats.getGet() == null ? null : totalStats.getGet().getExistsTime());
table.addCell(primaryStats.getGet() == null ? null : primaryStats.getGet().getExistsTime());
table.addCell(totalStats.getGet() == null ? null : totalStats.getGet().getExistsCount());
table.addCell(primaryStats.getGet() == null ? null : primaryStats.getGet().getExistsCount());
table.addCell(totalStats.getGet() == null ? null : totalStats.getGet().getMissingTime());
table.addCell(primaryStats.getGet() == null ? null : primaryStats.getGet().getMissingTime());
table.addCell(totalStats.getGet() == null ? null : totalStats.getGet().getMissingCount());
table.addCell(primaryStats.getGet() == null ? null : primaryStats.getGet().getMissingCount());
table.addCell(totalStats.getIndexing() == null ? null : totalStats.getIndexing().getTotal().getDeleteCurrent());
table.addCell(primaryStats.getIndexing() == null ? null : primaryStats.getIndexing().getTotal().getDeleteCurrent());
table.addCell(totalStats.getIndexing() == null ? null : totalStats.getIndexing().getTotal().getDeleteTime());
table.addCell(primaryStats.getIndexing() == null ? null : primaryStats.getIndexing().getTotal().getDeleteTime());
table.addCell(totalStats.getIndexing() == null ? null : totalStats.getIndexing().getTotal().getDeleteCount());
table.addCell(primaryStats.getIndexing() == null ? null : primaryStats.getIndexing().getTotal().getDeleteCount());
table.addCell(totalStats.getIndexing() == null ? null : totalStats.getIndexing().getTotal().getIndexCurrent());
table.addCell(primaryStats.getIndexing() == null ? null : primaryStats.getIndexing().getTotal().getIndexCurrent());
table.addCell(totalStats.getIndexing() == null ? null : totalStats.getIndexing().getTotal().getIndexTime());
table.addCell(primaryStats.getIndexing() == null ? null : primaryStats.getIndexing().getTotal().getIndexTime());
table.addCell(totalStats.getIndexing() == null ? null : totalStats.getIndexing().getTotal().getIndexCount());
table.addCell(primaryStats.getIndexing() == null ? null : primaryStats.getIndexing().getTotal().getIndexCount());
table.addCell(totalStats.getIndexing() == null ? null : totalStats.getIndexing().getTotal().getIndexFailedCount());
table.addCell(primaryStats.getIndexing() == null ? null : primaryStats.getIndexing().getTotal().getIndexFailedCount());
table.addCell(totalStats.getMerge() == null ? null : totalStats.getMerge().getCurrent());
table.addCell(primaryStats.getMerge() == null ? null : primaryStats.getMerge().getCurrent());
table.addCell(totalStats.getMerge() == null ? null : totalStats.getMerge().getCurrentNumDocs());
table.addCell(primaryStats.getMerge() == null ? null : primaryStats.getMerge().getCurrentNumDocs());
table.addCell(totalStats.getMerge() == null ? null : totalStats.getMerge().getCurrentSize());
table.addCell(primaryStats.getMerge() == null ? null : primaryStats.getMerge().getCurrentSize());
table.addCell(totalStats.getMerge() == null ? null : totalStats.getMerge().getTotal());
table.addCell(primaryStats.getMerge() == null ? null : primaryStats.getMerge().getTotal());
table.addCell(totalStats.getMerge() == null ? null : totalStats.getMerge().getTotalNumDocs());
table.addCell(primaryStats.getMerge() == null ? null : primaryStats.getMerge().getTotalNumDocs());
table.addCell(totalStats.getMerge() == null ? null : totalStats.getMerge().getTotalSize());
table.addCell(primaryStats.getMerge() == null ? null : primaryStats.getMerge().getTotalSize());
table.addCell(totalStats.getMerge() == null ? null : totalStats.getMerge().getTotalTime());
table.addCell(primaryStats.getMerge() == null ? null : primaryStats.getMerge().getTotalTime());
table.addCell(totalStats.getRefresh() == null ? null : totalStats.getRefresh().getTotal());
table.addCell(primaryStats.getRefresh() == null ? null : primaryStats.getRefresh().getTotal());
table.addCell(totalStats.getRefresh() == null ? null : totalStats.getRefresh().getTotalTime());
table.addCell(primaryStats.getRefresh() == null ? null : primaryStats.getRefresh().getTotalTime());
table.addCell(totalStats.getRefresh() == null ? null : totalStats.getRefresh().getExternalTotal());
table.addCell(primaryStats.getRefresh() == null ? null : primaryStats.getRefresh().getExternalTotal());
table.addCell(totalStats.getRefresh() == null ? null : totalStats.getRefresh().getExternalTotalTime());
table.addCell(primaryStats.getRefresh() == null ? null : primaryStats.getRefresh().getExternalTotalTime());
table.addCell(totalStats.getRefresh() == null ? null : totalStats.getRefresh().getListeners());
table.addCell(primaryStats.getRefresh() == null ? null : primaryStats.getRefresh().getListeners());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getFetchCurrent());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getFetchCurrent());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getFetchTime());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getFetchTime());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getFetchCount());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getFetchCount());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getOpenContexts());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getOpenContexts());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getQueryCurrent());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getQueryCurrent());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getQueryTime());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getQueryTime());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getQueryCount());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getQueryCount());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getScrollCurrent());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getScrollCurrent());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getScrollTime());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getScrollTime());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getScrollCount());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getScrollCount());
table.addCell(totalStats.getSegments() == null ? null : totalStats.getSegments().getCount());
table.addCell(primaryStats.getSegments() == null ? null : primaryStats.getSegments().getCount());
table.addCell(totalStats.getSegments() == null ? null : totalStats.getSegments().getMemory());
table.addCell(primaryStats.getSegments() == null ? null : primaryStats.getSegments().getMemory());
table.addCell(totalStats.getSegments() == null ? null : totalStats.getSegments().getIndexWriterMemory());
table.addCell(primaryStats.getSegments() == null ? null : primaryStats.getSegments().getIndexWriterMemory());
table.addCell(totalStats.getSegments() == null ? null : totalStats.getSegments().getVersionMapMemory());
table.addCell(primaryStats.getSegments() == null ? null : primaryStats.getSegments().getVersionMapMemory());
table.addCell(totalStats.getSegments() == null ? null : totalStats.getSegments().getBitsetMemory());
table.addCell(primaryStats.getSegments() == null ? null : primaryStats.getSegments().getBitsetMemory());
table.addCell(totalStats.getWarmer() == null ? null : totalStats.getWarmer().current());
table.addCell(primaryStats.getWarmer() == null ? null : primaryStats.getWarmer().current());
table.addCell(totalStats.getWarmer() == null ? null : totalStats.getWarmer().total());
table.addCell(primaryStats.getWarmer() == null ? null : primaryStats.getWarmer().total());
table.addCell(totalStats.getWarmer() == null ? null : totalStats.getWarmer().totalTime());
table.addCell(primaryStats.getWarmer() == null ? null : primaryStats.getWarmer().totalTime());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getSuggestCurrent());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getSuggestCurrent());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getSuggestTime());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getSuggestTime());
table.addCell(totalStats.getSearch() == null ? null : totalStats.getSearch().getTotal().getSuggestCount());
table.addCell(primaryStats.getSearch() == null ? null : primaryStats.getSearch().getTotal().getSuggestCount());
table.addCell(totalStats.getTotalMemory());
table.addCell(primaryStats.getTotalMemory());
table.addCell(searchThrottled);
table.endRow();
});
return table;
}