|
@@ -19,8 +19,7 @@
|
|
|
|
|
|
package org.elasticsearch.rest.action.cat;
|
|
|
|
|
|
-import com.carrotsearch.hppc.ObjectLongHashMap;
|
|
|
-import com.carrotsearch.hppc.ObjectLongMap;
|
|
|
+import com.carrotsearch.hppc.cursors.ObjectLongCursor;
|
|
|
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
|
|
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest;
|
|
|
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
|
@@ -36,11 +35,6 @@ import org.elasticsearch.rest.RestResponse;
|
|
|
import org.elasticsearch.rest.action.support.RestResponseListener;
|
|
|
import org.elasticsearch.rest.action.support.RestTable;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
|
|
|
|
|
/**
|
|
@@ -57,7 +51,6 @@ public class RestFielddataAction extends AbstractCatAction {
|
|
|
|
|
|
@Override
|
|
|
protected void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
|
|
-
|
|
|
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("data:true");
|
|
|
nodesStatsRequest.clear();
|
|
|
nodesStatsRequest.indices(true);
|
|
@@ -86,56 +79,30 @@ public class RestFielddataAction extends AbstractCatAction {
|
|
|
.addCell("host", "alias:h;desc:host name")
|
|
|
.addCell("ip", "desc:ip address")
|
|
|
.addCell("node", "alias:n;desc:node name")
|
|
|
- .addCell("total", "text-align:right;desc:total field data usage")
|
|
|
+ .addCell("field", "alias:f;desc:field name")
|
|
|
+ .addCell("size", "text-align:right;alias:s;desc:field data usage")
|
|
|
.endHeaders();
|
|
|
return table;
|
|
|
}
|
|
|
|
|
|
private Table buildTable(final RestRequest request, final NodesStatsResponse nodeStatses) {
|
|
|
- Set<String> fieldNames = new HashSet<>();
|
|
|
- Map<NodeStats, ObjectLongMap<String>> nodesFields = new HashMap<>();
|
|
|
-
|
|
|
- // Collect all the field names so a new table can be built
|
|
|
- for (NodeStats ns : nodeStatses.getNodes()) {
|
|
|
- ObjectLongHashMap<String> fields = ns.getIndices().getFieldData().getFields();
|
|
|
- nodesFields.put(ns, fields);
|
|
|
- if (fields != null) {
|
|
|
- for (String key : fields.keys().toArray(String.class)) {
|
|
|
- fieldNames.add(key);
|
|
|
+ Table table = getTableWithHeader(request);
|
|
|
+
|
|
|
+ for (NodeStats nodeStats: nodeStatses.getNodes()) {
|
|
|
+ if (nodeStats.getIndices().getFieldData().getFields() != null) {
|
|
|
+ for (ObjectLongCursor<String> cursor : nodeStats.getIndices().getFieldData().getFields()) {
|
|
|
+ table.startRow();
|
|
|
+ table.addCell(nodeStats.getNode().getId());
|
|
|
+ table.addCell(nodeStats.getNode().getHostName());
|
|
|
+ table.addCell(nodeStats.getNode().getHostAddress());
|
|
|
+ table.addCell(nodeStats.getNode().getName());
|
|
|
+ table.addCell(cursor.key);
|
|
|
+ table.addCell(new ByteSizeValue(cursor.value));
|
|
|
+ table.endRow();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // The table must be rebuilt because it has dynamic headers based on the fields
|
|
|
- Table table = new Table();
|
|
|
- table.startHeaders()
|
|
|
- .addCell("id", "desc:node id")
|
|
|
- .addCell("host", "alias:h;desc:host name")
|
|
|
- .addCell("ip", "desc:ip address")
|
|
|
- .addCell("node", "alias:n;desc:node name")
|
|
|
- .addCell("total", "text-align:right;desc:total field data usage");
|
|
|
- // The table columns must be built dynamically since the number of fields is unknown
|
|
|
- for (String fieldName : fieldNames) {
|
|
|
- table.addCell(fieldName, "text-align:right;desc:" + fieldName + " field");
|
|
|
- }
|
|
|
- table.endHeaders();
|
|
|
-
|
|
|
- for (Map.Entry<NodeStats, ObjectLongMap<String>> statsEntry : nodesFields.entrySet()) {
|
|
|
- table.startRow();
|
|
|
- // add the node info and field data total before each individual field
|
|
|
- NodeStats ns = statsEntry.getKey();
|
|
|
- table.addCell(ns.getNode().getId());
|
|
|
- table.addCell(ns.getNode().getHostName());
|
|
|
- table.addCell(ns.getNode().getHostAddress());
|
|
|
- table.addCell(ns.getNode().getName());
|
|
|
- table.addCell(ns.getIndices().getFieldData().getMemorySize());
|
|
|
- ObjectLongMap<String> fields = statsEntry.getValue();
|
|
|
- for (String fieldName : fieldNames) {
|
|
|
- table.addCell(new ByteSizeValue(fields == null ? 0L : fields.getOrDefault(fieldName, 0L)));
|
|
|
- }
|
|
|
- table.endRow();
|
|
|
- }
|
|
|
-
|
|
|
return table;
|
|
|
}
|
|
|
}
|