diff --git a/docs/reference/indices/stats.asciidoc b/docs/reference/indices/stats.asciidoc index b0dd311ed4d..e51ec117bf2 100644 --- a/docs/reference/indices/stats.asciidoc +++ b/docs/reference/indices/stats.asciidoc @@ -45,6 +45,7 @@ specified as well in the URI. Those stats can be any of: `flush`:: Flush statistics. `completion`:: Completion suggest statistics. `refresh`:: Refresh statistics. +`suggest`:: Suggest statistics. Some statistics allow per field granularity which accepts a list comma-separated list of included fields. By default all fields are included: diff --git a/rest-api-spec/api/indices.stats.json b/rest-api-spec/api/indices.stats.json index 2e2a529aa6c..c961d1e5e7b 100644 --- a/rest-api-spec/api/indices.stats.json +++ b/rest-api-spec/api/indices.stats.json @@ -17,7 +17,7 @@ }, "metric" : { "type" : "list", - "options" : ["_all", "completion", "docs", "fielddata", "filter_cache", "flush", "get", "id_cache", "indexing", "merge", "percolate", "refresh", "search", "segments", "store", "warmer"], + "options" : ["_all", "completion", "docs", "fielddata", "filter_cache", "flush", "get", "id_cache", "indexing", "merge", "percolate", "refresh", "search", "segments", "store", "warmer", "suggest"], "description" : "Limit the information returned the specific metrics." } }, diff --git a/rest-api-spec/api/nodes.stats.json b/rest-api-spec/api/nodes.stats.json index 8bf5224849d..7a795f59361 100644 --- a/rest-api-spec/api/nodes.stats.json +++ b/rest-api-spec/api/nodes.stats.json @@ -20,7 +20,7 @@ }, "index_metric" : { "type" : "list", - "options" : ["_all", "completion", "docs", "fielddata", "filter_cache", "flush", "get", "id_cache", "indexing", "merge", "percolate", "refresh", "search", "segments", "store", "warmer"], + "options" : ["_all", "completion", "docs", "fielddata", "filter_cache", "flush", "get", "id_cache", "indexing", "merge", "percolate", "refresh", "search", "segments", "store", "warmer", "suggest"], "description" : "Limit the information returned for `indices` metric to the specific index metrics. Isn't used if `indices` (or `all`) metric isn't specified." }, "node_id": { diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStats.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStats.java index 7bb490b7cbf..a4dd48384d6 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStats.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStats.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.admin.indices.stats; +import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -39,6 +40,7 @@ import org.elasticsearch.index.search.stats.SearchStats; import org.elasticsearch.index.shard.DocsStats; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.index.store.StoreStats; +import org.elasticsearch.index.suggest.stats.SuggestStats; import org.elasticsearch.index.translog.TranslogStats; import org.elasticsearch.index.warmer.WarmerStats; import org.elasticsearch.search.suggest.completion.CompletionStats; @@ -106,6 +108,9 @@ public class CommonStats implements Streamable, ToXContent { case Translog: translog = new TranslogStats(); break; + case Suggest: + suggest = new SuggestStats(); + break; default: throw new IllegalStateException("Unknown Flag: " + flag); } @@ -166,6 +171,9 @@ public class CommonStats implements Streamable, ToXContent { case Translog: translog = indexShard.translogStats(); break; + case Suggest: + suggest = indexShard.suggestStats(); + break; default: throw new IllegalStateException("Unknown Flag: " + flag); } @@ -220,6 +228,9 @@ public class CommonStats implements Streamable, ToXContent { @Nullable public TranslogStats translog; + @Nullable + public SuggestStats suggest; + public void add(CommonStats stats) { if (docs == null) { if (stats.getDocs() != null) { @@ -351,6 +362,14 @@ public class CommonStats implements Streamable, ToXContent { } else { translog.add(stats.getTranslog()); } + if (suggest == null) { + if (stats.getSuggest() != null) { + suggest = new SuggestStats(); + suggest.add(stats.getSuggest()); + } + } else { + suggest.add(stats.getSuggest()); + } } @Nullable @@ -429,7 +448,14 @@ public class CommonStats implements Streamable, ToXContent { } @Nullable - public TranslogStats getTranslog() { return translog; } + public TranslogStats getTranslog() { + return translog; + } + + @Nullable + public SuggestStats getSuggest() { + return suggest; + } public static CommonStats readCommonStats(StreamInput in) throws IOException { CommonStats stats = new CommonStats(); @@ -485,6 +511,9 @@ public class CommonStats implements Streamable, ToXContent { segments = SegmentsStats.readSegmentsStats(in); } translog = in.readOptionalStreamable(new TranslogStats()); + if (in.getVersion().onOrAfter(Version.V_1_2_0)) { + suggest = in.readOptionalStreamable(new SuggestStats()); + } } @Override @@ -580,6 +609,9 @@ public class CommonStats implements Streamable, ToXContent { segments.writeTo(out); } out.writeOptionalStreamable(translog); + if (out.getVersion().onOrAfter(Version.V_1_2_0)) { + out.writeOptionalStreamable(suggest); + } } // note, requires a wrapping object @@ -633,6 +665,9 @@ public class CommonStats implements Streamable, ToXContent { if (translog != null) { translog.toXContent(builder, params); } + if (suggest != null) { + suggest.toXContent(builder, params); + } return builder; } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStatsFlags.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStatsFlags.java index 52cb8b30482..4a3ac9bac93 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStatsFlags.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/CommonStatsFlags.java @@ -223,7 +223,8 @@ public class CommonStatsFlags implements Streamable, Cloneable { Percolate("percolate"), Completion("completion"), Segments("segments"), - Translog("translog"); + Translog("translog"), + Suggest("suggest"); private final String restName; diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequest.java index 13a626987d1..43da6b8764e 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequest.java @@ -247,6 +247,15 @@ public class IndicesStatsRequest extends BroadcastOperationRequest listener) { ((IndicesAdminClient) client).stats(request, listener); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java index 26511e73334..8fefe53ac20 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java @@ -193,6 +193,9 @@ public class TransportIndicesStatsAction extends TransportBroadcastOperationActi if (request.request.translog()) { flags.set(CommonStatsFlags.Flag.Translog); } + if (request.request.suggest()) { + flags.set(CommonStatsFlags.Flag.Suggest); + } return new ShardStats(indexShard, flags); } diff --git a/src/main/java/org/elasticsearch/action/suggest/TransportSuggestAction.java b/src/main/java/org/elasticsearch/action/suggest/TransportSuggestAction.java index 821934dafcf..cc7770fb0a0 100644 --- a/src/main/java/org/elasticsearch/action/suggest/TransportSuggestAction.java +++ b/src/main/java/org/elasticsearch/action/suggest/TransportSuggestAction.java @@ -39,6 +39,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.service.IndexService; import org.elasticsearch.index.shard.service.IndexShard; +import org.elasticsearch.index.suggest.stats.ShardSuggestService; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.search.suggest.Suggest; import org.elasticsearch.search.suggest.SuggestPhase; @@ -150,6 +151,9 @@ public class TransportSuggestAction extends TransportBroadcastOperationAction nodeIdsWithIndex = nodeIdsWithIndex("test1", "test2"); + int num = 0; + for (NodeStats stat : nodes) { + SuggestStats suggestStats = stat.getIndices().getSuggest(); + if (nodeIdsWithIndex.contains(stat.getNode().getId())) { + assertThat(suggestStats.getCount(), greaterThan(0l)); + assertThat(suggestStats.getTimeInMillis(), greaterThan(0l)); + num++; + } else { + assertThat(suggestStats.getCount(), equalTo(0l)); + assertThat(suggestStats.getTimeInMillis(), equalTo(0l)); + } + } + + assertThat(num, greaterThan(0)); + + } + + private Set nodeIdsWithIndex(String... indices) { + ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState(); + GroupShardsIterator allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); + Set nodes = new HashSet(); + for (ShardIterator shardIterator : allAssignedShardsGrouped) { + for (ShardRouting routing : shardIterator.asUnordered()) { + if (routing.active()) { + nodes.add(routing.currentNodeId()); + } + + } + } + return nodes; + } + + + protected int numAssignedShards(String... indices) { + ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState(); + GroupShardsIterator allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); + return allAssignedShardsGrouped.size(); + } +} diff --git a/src/test/java/org/elasticsearch/indices/stats/SimpleIndexStatsTests.java b/src/test/java/org/elasticsearch/indices/stats/SimpleIndexStatsTests.java index 878a5978669..38e219cfd78 100644 --- a/src/test/java/org/elasticsearch/indices/stats/SimpleIndexStatsTests.java +++ b/src/test/java/org/elasticsearch/indices/stats/SimpleIndexStatsTests.java @@ -315,7 +315,7 @@ public class SimpleIndexStatsTests extends ElasticsearchIntegrationTest { @Test public void testFlagOrdinalOrder() { Flag[] flags = new Flag[]{Flag.Store, Flag.Indexing, Flag.Get, Flag.Search, Flag.Merge, Flag.Flush, Flag.Refresh, - Flag.FilterCache, Flag.IdCache, Flag.FieldData, Flag.Docs, Flag.Warmer, Flag.Percolate, Flag.Completion, Flag.Segments, Flag.Translog}; + Flag.FilterCache, Flag.IdCache, Flag.FieldData, Flag.Docs, Flag.Warmer, Flag.Percolate, Flag.Completion, Flag.Segments, Flag.Translog, Flag.Suggest}; assertThat(flags.length, equalTo(Flag.values().length)); for (int i = 0; i < flags.length; i++) { @@ -373,6 +373,9 @@ public class SimpleIndexStatsTests extends ElasticsearchIntegrationTest { case Translog: builder.setTranslog(set); break; + case Suggest: + builder.setSuggest(set); + break; default: fail("new flag? " + flag); break; @@ -413,6 +416,8 @@ public class SimpleIndexStatsTests extends ElasticsearchIntegrationTest { return response.getSegments() != null; case Translog: return response.getTranslog() != null; + case Suggest: + return response.getSuggest() != null; default: fail("new flag? " + flag); return false;