Skip to content

Commit fdc301f

Browse files
authored
[Rest Api Compatibility] Typed indexing stats (#74181)
the per type indexing stats is simplified and when _types is requested it will return total stats for the index repeated under types/_doc/ the removal #47203 relates main meta issue #51816 relates types removal issue #54160
1 parent 2350369 commit fdc301f

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

rest-api-spec/build.gradle

+15-10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def v7compatiblityNotSupportedTests = {
6565
'mget/16_basic_with_types/Basic multi-get',
6666
// asserting about type not found won't work as we ignore the type information
6767
'explain/40_mix_typeless_typeful/Explain with typeless API on an index that has types',
68+
// translog settings removal is not supported under compatible api
69+
'indices.stats/20_translog/Translog retention settings are deprecated',
70+
'indices.stats/20_translog/Translog retention without soft_deletes',
71+
'indices.stats/20_translog/Translog stats on closed indices without soft-deletes'
6872
]
6973
}
7074
tasks.named("yamlRestCompatTest").configure {
@@ -86,16 +90,6 @@ tasks.named("yamlRestCompatTest").configure {
8690
'indices.put_template/11_basic_with_types/Put template with empty mappings',
8791
'indices.shrink/30_copy_settings/Copy settings during shrink index',
8892
'indices.split/30_copy_settings/Copy settings during split index',
89-
'indices.stats/15_types/Types - _all metric',
90-
'indices.stats/15_types/Types - indexing metric',
91-
'indices.stats/15_types/Types - multi',
92-
'indices.stats/15_types/Types - multi metric',
93-
'indices.stats/15_types/Types - one',
94-
'indices.stats/15_types/Types - pattern',
95-
'indices.stats/15_types/Types - star',
96-
'indices.stats/20_translog/Translog retention settings are deprecated',
97-
'indices.stats/20_translog/Translog retention without soft_deletes',
98-
'indices.stats/20_translog/Translog stats on closed indices without soft-deletes',
9993
'indices.upgrade/10_basic/Basic test for upgrade indices',
10094
'indices.upgrade/10_basic/Upgrade indices allow no indices',
10195
'indices.upgrade/10_basic/Upgrade indices disallow no indices',
@@ -236,6 +230,17 @@ tasks.named("transformV7RestTests").configure({ task ->
236230
task.replaceValueInMatch("docs.0._type", "_doc", "IDs")
237231
task.replaceValueInMatch("docs.1._type", "_doc", "IDs")
238232
task.replaceValueInMatch("docs.2._type", "_doc", "Routing")
233+
234+
//overrides for indices.stats
235+
//TODO fix to remove the below match
236+
task.replaceKeyInMatch("_all.primaries.indexing.types.baz.index_total",
237+
"_all.primaries.indexing.types._doc.index_total"
238+
)
239+
task.replaceKeyInMatch("_all.primaries.indexing.types.bar.index_total",
240+
"_all.primaries.indexing.types._doc.index_total"
241+
)
242+
task.replaceValueInMatch("_all.primaries.indexing.types._doc.index_total", 2)
243+
239244
})
240245

241246
tasks.register('enforceYamlTestConvention').configure {

server/src/main/java/org/elasticsearch/index/shard/IndexingStats.java

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.common.io.stream.StreamOutput;
1414
import org.elasticsearch.common.io.stream.Writeable;
15+
import org.elasticsearch.core.RestApiVersion;
1516
import org.elasticsearch.core.TimeValue;
1617
import org.elasticsearch.common.xcontent.ToXContent;
1718
import org.elasticsearch.common.xcontent.ToXContentFragment;
@@ -214,12 +215,20 @@ public Stats getTotal() {
214215
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
215216
builder.startObject(Fields.INDEXING);
216217
totalStats.toXContent(builder, params);
218+
if(builder.getRestApiVersion() == RestApiVersion.V_7 && params.param("types") != null){
219+
builder.startObject(Fields.TYPES);
220+
builder.startObject(MapperService.SINGLE_MAPPING_NAME);
221+
totalStats.toXContent(builder, params);
222+
builder.endObject();
223+
builder.endObject();
224+
}
217225
builder.endObject();
218226
return builder;
219227
}
220228

221229
static final class Fields {
222230
static final String INDEXING = "indexing";
231+
static final String TYPES = "types";
223232
static final String INDEX_TOTAL = "index_total";
224233
static final String INDEX_TIME = "index_time";
225234
static final String INDEX_TIME_IN_MILLIS = "index_time_in_millis";

server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag;
1414
import org.elasticsearch.client.node.NodeClient;
1515
import org.elasticsearch.common.Strings;
16+
import org.elasticsearch.common.logging.DeprecationLogger;
17+
import org.elasticsearch.core.RestApiVersion;
1618
import org.elasticsearch.rest.BaseRestHandler;
1719
import org.elasticsearch.rest.RestRequest;
1820
import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener;
@@ -31,6 +33,9 @@
3133
import static org.elasticsearch.rest.RestRequest.Method.GET;
3234

3335
public class RestNodesStatsAction extends BaseRestHandler {
36+
private DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestNodesStatsAction.class);
37+
private static final String TYPES_DEPRECATION_MESSAGE =
38+
"[types removal] " + "Specifying types in nodes stats requests is deprecated.";
3439

3540
@Override
3641
public List<Route> routes() {
@@ -71,6 +76,11 @@ public String getName() {
7176

7277
@Override
7378
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
79+
if(request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("types")){
80+
deprecationLogger.compatibleApiWarning("nodes_stats_types", TYPES_DEPRECATION_MESSAGE);
81+
request.param("types");
82+
}
83+
7484
String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
7585
Set<String> metrics = Strings.tokenizeByCommaToSet(request.param("metric", "_all"));
7686

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java

+11
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
import org.elasticsearch.action.support.IndicesOptions;
1515
import org.elasticsearch.client.node.NodeClient;
1616
import org.elasticsearch.common.Strings;
17+
import org.elasticsearch.common.logging.DeprecationLogger;
18+
import org.elasticsearch.core.RestApiVersion;
1719
import org.elasticsearch.rest.BaseRestHandler;
1820
import org.elasticsearch.rest.RestRequest;
1921
import org.elasticsearch.rest.action.RestCancellableNodeClient;
2022
import org.elasticsearch.rest.action.RestToXContentListener;
23+
import org.elasticsearch.rest.action.document.RestMultiTermVectorsAction;
2124

2225
import java.io.IOException;
2326
import java.util.Collections;
@@ -32,6 +35,9 @@
3235
import static org.elasticsearch.rest.RestRequest.Method.GET;
3336

3437
public class RestIndicesStatsAction extends BaseRestHandler {
38+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestMultiTermVectorsAction.class);
39+
private static final String TYPES_DEPRECATION_MESSAGE =
40+
"[types removal] " + "Specifying types in indices stats requests is deprecated.";
3541

3642
@Override
3743
public List<Route> routes() {
@@ -64,6 +70,11 @@ public boolean allowSystemIndexAccessByDefault() {
6470

6571
@Override
6672
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
73+
if(request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("types")){
74+
deprecationLogger.compatibleApiWarning("indices_stats_types", TYPES_DEPRECATION_MESSAGE);
75+
request.param("types");
76+
}
77+
6778
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
6879
boolean forbidClosedIndices = request.paramAsBoolean("forbid_closed_indices", true);
6980
IndicesOptions defaultIndicesOption = forbidClosedIndices ? indicesStatsRequest.indicesOptions()

server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import static org.elasticsearch.rest.RestRequest.Method.POST;
2727

2828
public class RestMultiTermVectorsAction extends BaseRestHandler {
29-
DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestMultiTermVectorsAction.class);
29+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestMultiTermVectorsAction.class);
3030
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] " + "Specifying types in multi term vector requests is deprecated.";
3131

3232
@Override

0 commit comments

Comments
 (0)