|
28 | 28 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
29 | 29 | import org.elasticsearch.index.cache.filter.FilterCacheStats;
|
30 | 30 | import org.elasticsearch.index.cache.id.IdCacheStats;
|
| 31 | +import org.elasticsearch.index.cache.query.QueryCacheStats; |
31 | 32 | import org.elasticsearch.index.engine.SegmentsStats;
|
32 | 33 | import org.elasticsearch.index.fielddata.FieldDataStats;
|
33 | 34 | import org.elasticsearch.index.flush.FlushStats;
|
@@ -111,6 +112,9 @@ public CommonStats(CommonStatsFlags flags) {
|
111 | 112 | case Suggest:
|
112 | 113 | suggest = new SuggestStats();
|
113 | 114 | break;
|
| 115 | + case QueryCache: |
| 116 | + queryCache = new QueryCacheStats(); |
| 117 | + break; |
114 | 118 | default:
|
115 | 119 | throw new IllegalStateException("Unknown Flag: " + flag);
|
116 | 120 | }
|
@@ -174,6 +178,9 @@ public CommonStats(IndexShard indexShard, CommonStatsFlags flags) {
|
174 | 178 | case Suggest:
|
175 | 179 | suggest = indexShard.suggestStats();
|
176 | 180 | break;
|
| 181 | + case QueryCache: |
| 182 | + queryCache = indexShard.queryCache().stats(); |
| 183 | + break; |
177 | 184 | default:
|
178 | 185 | throw new IllegalStateException("Unknown Flag: " + flag);
|
179 | 186 | }
|
@@ -231,6 +238,9 @@ public CommonStats(IndexShard indexShard, CommonStatsFlags flags) {
|
231 | 238 | @Nullable
|
232 | 239 | public SuggestStats suggest;
|
233 | 240 |
|
| 241 | + @Nullable |
| 242 | + public QueryCacheStats queryCache; |
| 243 | + |
234 | 244 | public void add(CommonStats stats) {
|
235 | 245 | if (docs == null) {
|
236 | 246 | if (stats.getDocs() != null) {
|
@@ -370,6 +380,14 @@ public void add(CommonStats stats) {
|
370 | 380 | } else {
|
371 | 381 | suggest.add(stats.getSuggest());
|
372 | 382 | }
|
| 383 | + if (queryCache == null) { |
| 384 | + if (stats.getQueryCache() != null) { |
| 385 | + queryCache = new QueryCacheStats(); |
| 386 | + queryCache.add(stats.getQueryCache()); |
| 387 | + } |
| 388 | + } else { |
| 389 | + queryCache.add(stats.getQueryCache()); |
| 390 | + } |
373 | 391 | }
|
374 | 392 |
|
375 | 393 | @Nullable
|
@@ -457,6 +475,11 @@ public SuggestStats getSuggest() {
|
457 | 475 | return suggest;
|
458 | 476 | }
|
459 | 477 |
|
| 478 | + @Nullable |
| 479 | + public QueryCacheStats getQueryCache() { |
| 480 | + return queryCache; |
| 481 | + } |
| 482 | + |
460 | 483 | public static CommonStats readCommonStats(StreamInput in) throws IOException {
|
461 | 484 | CommonStats stats = new CommonStats();
|
462 | 485 | stats.readFrom(in);
|
@@ -514,6 +537,9 @@ public void readFrom(StreamInput in) throws IOException {
|
514 | 537 | if (in.getVersion().onOrAfter(Version.V_1_2_0)) {
|
515 | 538 | suggest = in.readOptionalStreamable(new SuggestStats());
|
516 | 539 | }
|
| 540 | + if (in.getVersion().onOrAfter(Version.V_1_4_0)) { |
| 541 | + queryCache = in.readOptionalStreamable(new QueryCacheStats()); |
| 542 | + } |
517 | 543 | }
|
518 | 544 |
|
519 | 545 | @Override
|
@@ -612,6 +638,9 @@ public void writeTo(StreamOutput out) throws IOException {
|
612 | 638 | if (out.getVersion().onOrAfter(Version.V_1_2_0)) {
|
613 | 639 | out.writeOptionalStreamable(suggest);
|
614 | 640 | }
|
| 641 | + if (out.getVersion().onOrAfter(Version.V_1_4_0)) { |
| 642 | + out.writeOptionalStreamable(queryCache); |
| 643 | + } |
615 | 644 | }
|
616 | 645 |
|
617 | 646 | // note, requires a wrapping object
|
@@ -668,6 +697,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
|
668 | 697 | if (suggest != null) {
|
669 | 698 | suggest.toXContent(builder, params);
|
670 | 699 | }
|
| 700 | + if (queryCache != null) { |
| 701 | + queryCache.toXContent(builder, params); |
| 702 | + } |
671 | 703 | return builder;
|
672 | 704 | }
|
673 | 705 | }
|
0 commit comments