From 85fcefc60de35a9972e1249a86534bea3509cf5d Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 16 Sep 2013 10:21:25 +0200 Subject: [PATCH] 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 --- docs/reference/indices/stats.asciidoc | 15 ++++++++++++--- .../indices/stats/RestIndicesStatsAction.java | 9 +++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/reference/indices/stats.asciidoc b/docs/reference/indices/stats.asciidoc index 0468a8cb202..26a154d5d27 100644 --- a/docs/reference/indices/stats.asciidoc +++ b/docs/reference/indices/stats.asciidoc @@ -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] diff --git a/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java b/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java index d3eca0eac0b..0431c539438 100644 --- a/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java +++ b/src/main/java/org/elasticsearch/rest/action/admin/indices/stats/RestIndicesStatsAction.java @@ -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() { @Override