diff --git a/CHANGELOG.md b/CHANGELOG.md index 14327a02e04f9..49c064bda97a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Add search replica stats to segment replication stats API ([#16678](https://github.com/opensearch-project/OpenSearch/pull/16678)) - Introduce framework for auxiliary transports and an experimental gRPC transport plugin ([#16534](https://github.com/opensearch-project/OpenSearch/pull/16534)) - Support searching from doc_value using termQueryCaseInsensitive/termQuery in flat_object/keyword field([#16974](https://github.com/opensearch-project/OpenSearch/pull/16974/)) +- Added a new `time` field to replace the deprecated `getTime` field in `GetStats`. ([#17009](https://github.com/opensearch-project/OpenSearch/pull/17009)) ### Dependencies - Bump `com.google.cloud:google-cloud-core-http` from 2.23.0 to 2.47.0 ([#16504](https://github.com/opensearch-project/OpenSearch/pull/16504)) @@ -69,6 +70,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Deprecated - Performing update operation with default pipeline or final pipeline is deprecated ([#16712](https://github.com/opensearch-project/OpenSearch/pull/16712)) +- Marked `getTime` field as deprecated in favor of the new `time` field. ([#17009](https://github.com/opensearch-project/OpenSearch/pull/17009)) ### Removed diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/60_include_both_time_and_gettime_in_stats.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/60_include_both_time_and_gettime_in_stats.yml new file mode 100644 index 0000000000000..d5e3e7554b400 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.stats/60_include_both_time_and_gettime_in_stats.yml @@ -0,0 +1,36 @@ +--- +setup: + - do: + indices.create: + index: test1 + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + wait_for_active_shards: all + + - do: + index: + index: test1 + id: 1 + body: { "foo": "bar" } + + - do: + indices.refresh: + index: test1 + +--- +"Test _stats API includes both time and getTime metrics with human filter": + - skip: + version: " - 2.19.99" + reason: "this change is added in 3.0.0" + + - do: + indices.stats: + metric: [ get ] + human: true + + - is_true: _all.primaries.get.time + - is_true: _all.primaries.get.getTime + - match: { _all.primaries.get.time: "0s" } + - match: { _all.primaries.get.getTime: "0s" } diff --git a/server/src/main/java/org/opensearch/index/get/GetStats.java b/server/src/main/java/org/opensearch/index/get/GetStats.java index a366014fe228e..55f14294d774b 100644 --- a/server/src/main/java/org/opensearch/index/get/GetStats.java +++ b/server/src/main/java/org/opensearch/index/get/GetStats.java @@ -41,6 +41,7 @@ import org.opensearch.core.xcontent.XContentBuilder; import java.io.IOException; +import java.util.Objects; /** * Stats for a search get @@ -137,6 +138,7 @@ public long current() { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.GET); builder.field(Fields.TOTAL, getCount()); + builder.field(Fields.GET_TIME, Objects.toString(getTime())); builder.humanReadableField(Fields.TIME_IN_MILLIS, Fields.TIME, getTime()); builder.field(Fields.EXISTS_TOTAL, existsCount); builder.humanReadableField(Fields.EXISTS_TIME_IN_MILLIS, Fields.EXISTS_TIME, getExistsTime()); @@ -155,7 +157,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws static final class Fields { static final String GET = "get"; static final String TOTAL = "total"; - static final String TIME = "getTime"; + /** + * Deprecated field name for time. Use {@link #TIME} instead. + */ + @Deprecated(forRemoval = true) + static final String GET_TIME = "getTime"; + static final String TIME = "time"; static final String TIME_IN_MILLIS = "time_in_millis"; static final String EXISTS_TOTAL = "exists_total"; static final String EXISTS_TIME = "exists_time";