Allow include / exclude of completion stats via REST parameters

Stats can be retrieved on a per-feature / per-component  basis including the fields
they apply to. This commit add support for a 'completion' flag to include statistics
for the complition feature as well as 'completion_fields' to only
include certain fields into the returned statistics.
To disambiguate between 'fielddata' and 'completion' fields this commit
uses 'fields' as the default inclusion filter for stats fields only used
if not dedicated '[completion|fielddata]_fields' paramter is provided.

Relates to #3522
This commit is contained in:
Simon Willnauer 2013-09-16 10:21:25 +02:00
parent f6f4b5014f
commit 85fcefc60d
2 changed files with 19 additions and 5 deletions

View File

@ -39,11 +39,20 @@ are returned, other stats can be enabled as well:
groups).
`warmer`:: Warmer statistics.
`merge`:: merge stats.
`flush`:: flush stats.
`refresh`:: refresh stats.
`merge`:: Merge statistics.
`fielddata`:: Fielddata statistics.
`flush`:: Flush statistics.
`completion`:: Completion suggest statistics.
`refresh`:: Refresh statistics.
`clear`:: Clears all the flags (first).
Some statistics allow per field granularity which accepts a list comma-separated list of included fields. By default all fields are included:
[horizontal]
`fields`:: List of fields to be included in the statistics. This is used as the default list unless a more specific field list is provided (see below).
`completion_fields`:: List of fields to be included in the Completion Suggest statistics
`fielddata_fields`:: List of fields to be included in the Fielddata statistics
Here are some samples:
[source,js]

View File

@ -35,7 +35,7 @@ import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.OK;
import static org.elasticsearch.rest.action.support.RestActions.*;
import static org.elasticsearch.rest.action.support.RestActions.buildBroadcastShardsHeader;
/**
*/
@ -118,6 +118,9 @@ public class RestIndicesStatsAction extends BaseRestHandler {
if (request.hasParam("groups")) {
indicesStatsRequest.groups(Strings.splitStringByCommaToArray(request.param("groups")));
}
/* We use "fields" as the default field list for stats that support field inclusion filters and further down
* a more specific list of fields that overrides this list.*/
final String[] defaultIncludedFields = request.paramAsStringArray("fields", null);
indicesStatsRequest.docs(request.paramAsBoolean("docs", indicesStatsRequest.docs()));
indicesStatsRequest.store(request.paramAsBoolean("store", indicesStatsRequest.store()));
indicesStatsRequest.indexing(request.paramAsBoolean("indexing", indicesStatsRequest.indexing()));
@ -130,8 +133,10 @@ public class RestIndicesStatsAction extends BaseRestHandler {
indicesStatsRequest.filterCache(request.paramAsBoolean("filter_cache", indicesStatsRequest.filterCache()));
indicesStatsRequest.idCache(request.paramAsBoolean("id_cache", indicesStatsRequest.idCache()));
indicesStatsRequest.fieldData(request.paramAsBoolean("fielddata", indicesStatsRequest.fieldData()));
indicesStatsRequest.fieldDataFields(request.paramAsStringArray("fields", null));
indicesStatsRequest.fieldDataFields(request.paramAsStringArray("fielddata_fields", defaultIncludedFields));
indicesStatsRequest.percolate(request.paramAsBoolean("percolate", indicesStatsRequest.percolate()));
indicesStatsRequest.completion(request.paramAsBoolean("completion", indicesStatsRequest.completion()));
indicesStatsRequest.completionFields(request.paramAsStringArray("completion_fields", defaultIncludedFields));
client.admin().indices().stats(indicesStatsRequest, new ActionListener<IndicesStatsResponse>() {
@Override