Merge branch 'pr/18068'
This commit is contained in:
commit
1c54033e92
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.rest.action.cat;
|
package org.elasticsearch.rest.action.cat;
|
||||||
|
|
||||||
import com.carrotsearch.hppc.ObjectLongHashMap;
|
import com.carrotsearch.hppc.cursors.ObjectLongCursor;
|
||||||
import com.carrotsearch.hppc.ObjectLongMap;
|
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
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.NodesStatsRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
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.RestResponseListener;
|
||||||
import org.elasticsearch.rest.action.support.RestTable;
|
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;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +51,6 @@ public class RestFielddataAction extends AbstractCatAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
protected void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||||
|
|
||||||
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("data:true");
|
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("data:true");
|
||||||
nodesStatsRequest.clear();
|
nodesStatsRequest.clear();
|
||||||
nodesStatsRequest.indices(true);
|
nodesStatsRequest.indices(true);
|
||||||
|
@ -86,55 +79,29 @@ public class RestFielddataAction extends AbstractCatAction {
|
||||||
.addCell("host", "alias:h;desc:host name")
|
.addCell("host", "alias:h;desc:host name")
|
||||||
.addCell("ip", "desc:ip address")
|
.addCell("ip", "desc:ip address")
|
||||||
.addCell("node", "alias:n;desc:node name")
|
.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();
|
.endHeaders();
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Table buildTable(final RestRequest request, final NodesStatsResponse nodeStatses) {
|
private Table buildTable(final RestRequest request, final NodesStatsResponse nodeStatses) {
|
||||||
Set<String> fieldNames = new HashSet<>();
|
Table table = getTableWithHeader(request);
|
||||||
Map<NodeStats, ObjectLongMap<String>> nodesFields = new HashMap<>();
|
|
||||||
|
|
||||||
// Collect all the field names so a new table can be built
|
for (NodeStats nodeStats: nodeStatses.getNodes()) {
|
||||||
for (NodeStats ns : nodeStatses.getNodes()) {
|
if (nodeStats.getIndices().getFieldData().getFields() != null) {
|
||||||
ObjectLongHashMap<String> fields = ns.getIndices().getFieldData().getFields();
|
for (ObjectLongCursor<String> cursor : nodeStats.getIndices().getFieldData().getFields()) {
|
||||||
nodesFields.put(ns, fields);
|
|
||||||
if (fields != null) {
|
|
||||||
for (String key : fields.keys().toArray(String.class)) {
|
|
||||||
fieldNames.add(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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();
|
table.startRow();
|
||||||
// add the node info and field data total before each individual field
|
table.addCell(nodeStats.getNode().getId());
|
||||||
NodeStats ns = statsEntry.getKey();
|
table.addCell(nodeStats.getNode().getHostName());
|
||||||
table.addCell(ns.getNode().getId());
|
table.addCell(nodeStats.getNode().getHostAddress());
|
||||||
table.addCell(ns.getNode().getHostName());
|
table.addCell(nodeStats.getNode().getName());
|
||||||
table.addCell(ns.getNode().getHostAddress());
|
table.addCell(cursor.key);
|
||||||
table.addCell(ns.getNode().getName());
|
table.addCell(new ByteSizeValue(cursor.value));
|
||||||
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();
|
table.endRow();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,13 @@ on every data node in the cluster.
|
||||||
[source,sh]
|
[source,sh]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
% curl '192.168.56.10:9200/_cat/fielddata?v'
|
% curl '192.168.56.10:9200/_cat/fielddata?v'
|
||||||
id host ip node total body text
|
id host ip node field size
|
||||||
c223lARiSGeezlbrcugAYQ myhost1 10.20.100.200 Jessica Jones 385.6kb 159.8kb 225.7kb
|
c223lARiSGeezlbrcugAYQ myhost1 10.20.100.200 Jessica Jones body 159.8kb
|
||||||
waPCbitNQaCL6xC8VxjAwg myhost2 10.20.100.201 Adversary 435.2kb 159.8kb 275.3kb
|
c223lARiSGeezlbrcugAYQ myhost1 10.20.100.200 Jessica Jones text 225.7kb
|
||||||
yaDkp-G3R0q1AJ-HUEvkSQ myhost3 10.20.100.202 Microchip 284.6kb 109.2kb 175.3kb
|
waPCbitNQaCL6xC8VxjAwg myhost2 10.20.100.201 Adversary body 159.8kb
|
||||||
|
waPCbitNQaCL6xC8VxjAwg myhost2 10.20.100.201 Adversary text 275.3kb
|
||||||
|
yaDkp-G3R0q1AJ-HUEvkSQ myhost3 10.20.100.202 Microchip body 109.2kb
|
||||||
|
yaDkp-G3R0q1AJ-HUEvkSQ myhost3 10.20.100.202 Microchip text 175.3kb
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
Fields can be specified either as a query parameter, or in the URL path:
|
Fields can be specified either as a query parameter, or in the URL path:
|
||||||
|
@ -18,17 +21,19 @@ Fields can be specified either as a query parameter, or in the URL path:
|
||||||
[source,sh]
|
[source,sh]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
% curl '192.168.56.10:9200/_cat/fielddata?v&fields=body'
|
% curl '192.168.56.10:9200/_cat/fielddata?v&fields=body'
|
||||||
id host ip node total body
|
id host ip node field size
|
||||||
c223lARiSGeezlbrcugAYQ myhost1 10.20.100.200 Jessica Jones 385.6kb 159.8kb
|
c223lARiSGeezlbrcugAYQ myhost1 10.20.100.200 Jessica Jones body 159.8kb
|
||||||
waPCbitNQaCL6xC8VxjAwg myhost2 10.20.100.201 Adversary 435.2kb 159.8kb
|
waPCbitNQaCL6xC8VxjAwg myhost2 10.20.100.201 Adversary body 159.8kb
|
||||||
yaDkp-G3R0q1AJ-HUEvkSQ myhost3 10.20.100.202 Microchip 284.6kb 109.2kb
|
yaDkp-G3R0q1AJ-HUEvkSQ myhost3 10.20.100.202 Microchip body 109.2kb
|
||||||
|
|
||||||
% curl '192.168.56.10:9200/_cat/fielddata/body,text?v'
|
% curl '192.168.56.10:9200/_cat/fielddata/body,text?v'
|
||||||
id host ip node total body text
|
id host ip node field size
|
||||||
c223lARiSGeezlbrcugAYQ myhost1 10.20.100.200 Jessica Jones 385.6kb 159.8kb 225.7kb
|
c223lARiSGeezlbrcugAYQ myhost1 10.20.100.200 Jessica Jones body 159.8kb
|
||||||
waPCbitNQaCL6xC8VxjAwg myhost2 10.20.100.201 Adversary 435.2kb 159.8kb 275.3kb
|
c223lARiSGeezlbrcugAYQ myhost1 10.20.100.200 Jessica Jones text 225.7kb
|
||||||
yaDkp-G3R0q1AJ-HUEvkSQ myhost3 10.20.100.202 Microchip 284.6kb 109.2kb 175.3kb
|
waPCbitNQaCL6xC8VxjAwg myhost2 10.20.100.201 Adversary body 159.8kb
|
||||||
|
waPCbitNQaCL6xC8VxjAwg myhost2 10.20.100.201 Adversary text 275.3kb
|
||||||
|
yaDkp-G3R0q1AJ-HUEvkSQ myhost3 10.20.100.202 Microchip body 109.2kb
|
||||||
|
yaDkp-G3R0q1AJ-HUEvkSQ myhost3 10.20.100.202 Microchip text 175.3kb
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
The output shows the total fielddata and then the individual fielddata for the
|
The output shows the individual fielddata for the`body` and `text` fields, one row per field per node.
|
||||||
`body` and `text` fields.
|
|
||||||
|
|
|
@ -38,3 +38,10 @@ and `i` for ingest. A node with no explicit roles will be a coordinating
|
||||||
only node and marked with `-`. A node can have multiple roles. The
|
only node and marked with `-`. A node can have multiple roles. The
|
||||||
master column has been adapted to return only whether a node is the
|
master column has been adapted to return only whether a node is the
|
||||||
current master (`*`) or not (`-`).
|
current master (`*`) or not (`-`).
|
||||||
|
|
||||||
|
==== Changes to cat field data API
|
||||||
|
|
||||||
|
The cat field data endpoint adds a row per field instead of a column per field.
|
||||||
|
|
||||||
|
The `total` field has been removed from the field data API. Total field data usage per node
|
||||||
|
can be got by cat nodes API.
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
host .+ \n
|
host .+ \n
|
||||||
ip .+ \n
|
ip .+ \n
|
||||||
node .+ \n
|
node .+ \n
|
||||||
total .+ \n
|
field .+ \n
|
||||||
|
size .+ \n
|
||||||
$/
|
$/
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -38,39 +39,41 @@
|
||||||
type: type
|
type: type
|
||||||
body: { foo: bar }
|
body: { foo: bar }
|
||||||
refresh: true
|
refresh: true
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
search:
|
search:
|
||||||
index: index
|
index: index
|
||||||
body:
|
body:
|
||||||
query: { match_all: {} }
|
query: { match_all: {} }
|
||||||
sort: foo
|
sort: foo
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
cat.fielddata:
|
cat.fielddata:
|
||||||
h: total
|
h: field,size
|
||||||
v: true
|
v: true
|
||||||
|
|
||||||
- match:
|
- match:
|
||||||
$body: |
|
$body: |
|
||||||
/^ total \n
|
/^ field \s+ size \n
|
||||||
(\s*\d+(\.\d+)?[gmk]?b \n)+ $/
|
foo \s+ (\d+(\.\d+)?[gmk]?b \n)+ $/
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
cat.fielddata:
|
cat.fielddata:
|
||||||
h: total,foo
|
h: field,size
|
||||||
v: true
|
|
||||||
|
|
||||||
- match:
|
|
||||||
$body: |
|
|
||||||
/^ total \s+ foo \n
|
|
||||||
(\s*\d+(\.\d+)?[gmk]?b \s+ \d+(\.\d+)?[gmk]?b \n)+ $/
|
|
||||||
|
|
||||||
- do:
|
|
||||||
cat.fielddata:
|
|
||||||
h: total,foo
|
|
||||||
fields: notfoo,foo
|
fields: notfoo,foo
|
||||||
v: true
|
v: true
|
||||||
|
|
||||||
- match:
|
- match:
|
||||||
$body: |
|
$body: |
|
||||||
/^ total \s+ foo \n
|
/^ field \s+ size \n
|
||||||
(\s*\d+(\.\d+)?[gmk]?b \s+ \d+(\.\d+)?[gmk]?b \n)+ $/
|
foo \s+ (\d+(\.\d+)?[gmk]?b \n)+ $/
|
||||||
|
|
||||||
|
- do:
|
||||||
|
cat.fielddata:
|
||||||
|
h: field,size
|
||||||
|
fields: notfoo
|
||||||
|
v: true
|
||||||
|
|
||||||
|
- match:
|
||||||
|
$body: |
|
||||||
|
/^ field \s+ size \n $/
|
||||||
|
|
Loading…
Reference in New Issue