Skip to content

Commit a614415

Browse files
authored
Remove deprecated sort options: nested_path and nested_filter (#42809)
This commit removes the nested_path and nested_filter options deprecated in 6x. This change also checks that the sort field has a [nested] option if it is under a nested object and throws an exception if it's not the case. Closes #27098
1 parent b77a6fc commit a614415

File tree

16 files changed

+257
-589
lines changed

16 files changed

+257
-589
lines changed

docs/reference/migration/migrate_8_0/search.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ The same functionality can be achieved by the `match` query if the total number
2020

2121
The `cutoff_frequency` parameter was deprecated in 7.x and has been removed in 8.0 from `match` and `multi_match` queries.
2222
The same functionality can be achieved without any configuration provided that the total number of hits is not tracked.
23+
24+
[float]
25+
===== Removal of sort parameters
26+
27+
The `nested_filter` and `nested_path` options, deprecated in 6.x, have been removed in favor of the `nested` context.

docs/reference/search/request/sort.asciidoc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,16 @@ field support has a `nested` sort option with the following properties:
252252
A filter that the inner objects inside the nested path
253253
should match with in order for its field values to be taken into account
254254
by sorting. Common case is to repeat the query / filter inside the
255-
nested filter or query. By default no `nested_filter` is active.
255+
nested filter or query. By default no `filter` is active.
256256
`max_children`::
257257
The maximum number of children to consider per root document
258258
when picking the sort value. Defaults to unlimited.
259259
`nested`::
260260
Same as top-level `nested` but applies to another nested path within the
261261
current nested object.
262262

263-
[WARNING]
264-
.Nested sort options before Elasticsearch 6.1
265-
============================================
266-
267-
The `nested_path` and `nested_filter` options have been deprecated in
268-
favor of the options documented above.
269-
270-
============================================
263+
NOTE: Elasticsearch will throw an error if a nested field is defined in a sort without
264+
a `nested` context.
271265

272266
===== Nested sorting examples
273267

@@ -300,7 +294,7 @@ POST /_search
300294
// CONSOLE
301295

302296
In the below example `parent` and `child` fields are of type `nested`.
303-
The `nested_path` needs to be specified at each level; otherwise, Elasticsearch doesn't know on what nested level sort values need to be captured.
297+
The `nested.path` needs to be specified at each level; otherwise, Elasticsearch doesn't know on what nested level sort values need to be captured.
304298

305299
[source,js]
306300
--------------------------------------------------
@@ -374,7 +368,7 @@ GET /_search
374368
// CONSOLE
375369

376370
NOTE: If a nested inner object doesn't match with
377-
the `nested_filter` then a missing value is used.
371+
the `nested.filter` then a missing value is used.
378372

379373
==== Ignoring Unmapped Fields
380374

rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/200_top_hits_metric.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,19 @@ setup:
9292
aggs:
9393
users:
9494
top_hits:
95-
sort: "users.last.keyword"
95+
sort:
96+
users.last.keyword:
97+
nested:
98+
path: users
9699
seq_no_primary_term: true
97100

98101
- match: { hits.total: 2 }
99102
- length: { aggregations.groups.buckets.0.users.hits.hits: 2 }
100-
- match: { aggregations.groups.buckets.0.users.hits.hits.0._id: "1" }
103+
- match: { aggregations.groups.buckets.0.users.hits.hits.0._id: "2" }
101104
- match: { aggregations.groups.buckets.0.users.hits.hits.0._index: my-index }
102105
- gte: { aggregations.groups.buckets.0.users.hits.hits.0._seq_no: 0 }
103106
- gte: { aggregations.groups.buckets.0.users.hits.hits.0._primary_term: 1 }
104-
- match: { aggregations.groups.buckets.0.users.hits.hits.1._id: "2" }
107+
- match: { aggregations.groups.buckets.0.users.hits.hits.1._id: "1" }
105108
- match: { aggregations.groups.buckets.0.users.hits.hits.1._index: my-index }
106109
- gte: { aggregations.groups.buckets.0.users.hits.hits.1._seq_no: 0 }
107110
- gte: { aggregations.groups.buckets.0.users.hits.hits.1._primary_term: 1 }

server/src/main/java/org/elasticsearch/index/search/NestedHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ boolean mightMatchNonNestedDocs(String field, String nestedPath) {
192192
return true; // the field is not a sub field of the nested path
193193
}
194194

195-
private static String parentObject(String field) {
195+
public static String parentObject(String field) {
196196
int lastDot = field.lastIndexOf('.');
197197
if (lastDot == -1) {
198198
return null;

0 commit comments

Comments
 (0)