Skip to content

Commit 646e1e9

Browse files
committed
Deprecate dots in aggregation names
Dots in aggregation names can lead to tricky parsing situations, like being unable to sort by agg names with dots. This adds a deprecation logger and a note in the docs, letting us remove them in 8.0. Related to elastic#17600 and elastic#19040
1 parent 90d62e6 commit 646e1e9

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

docs/reference/aggregations.asciidoc

+7-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ The following snippet captures the basic structure of aggregations:
6767
The `aggregations` object (the key `aggs` can also be used) in the JSON holds the aggregations to be computed. Each aggregation
6868
is associated with a logical name that the user defines (e.g. if the aggregation computes the average price, then it would
6969
make sense to name it `avg_price`). These logical names will also be used to uniquely identify the aggregations in the
70-
response. Each aggregation has a specific type (`<aggregation_type>` in the above snippet) and is typically the first
70+
response.
71+
72+
Aggregation names can be any alphanumeric character except a left bracket (`[`), right bracket (`]`) or greater-than sign (`>`).
73+
74+
deprecated[6.4.0, Periods in aggregations names have been deprecated, and will be removed in `8.0.0`.]
75+
76+
Each aggregation has a specific type (`<aggregation_type>` in the above snippet) and is typically the first
7177
key within the named aggregation body. Each type of aggregation defines its own body, depending on the nature of the
7278
aggregation (e.g. an `avg` aggregation on a specific field will define the field on which the average will be calculated).
7379
At the same level of the aggregation type definition, one can optionally define a set of additional aggregations,

docs/reference/migration/migrate_7_0/aggregations.asciidoc

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ Requests that try to return more than the limit will fail with an exception.
1414
==== `missing` option of the `composite` aggregation has been removed
1515

1616
The `missing` option of the `composite` aggregation, deprecated in 6.x,
17-
has been removed. `missing_bucket` should be used instead.
17+
has been removed. `missing_bucket` should be used instead.
18+
19+
==== Dots in aggregation names have been deprecated
20+
21+
Starting in 6.4.0, dots in aggregation names have been deprecated. Aggregation names that use
22+
dots will start to throw exceptions in 8.0.0.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
setup:
2+
- do:
3+
indices.create:
4+
index: test_1
5+
body:
6+
settings:
7+
number_of_replicas: 0
8+
mappings:
9+
doc:
10+
properties:
11+
int_field:
12+
type : integer
13+
double_field:
14+
type : double
15+
string_field:
16+
type: keyword
17+
18+
- do:
19+
bulk:
20+
refresh: true
21+
body:
22+
- index:
23+
_index: test_1
24+
_type: doc
25+
_id: 1
26+
- int_field: 1
27+
double_field: 1.0
28+
string_field: foo
29+
- index:
30+
_index: test_1
31+
_type: doc
32+
_id: 2
33+
- int_field: 51
34+
double_field: 51.0
35+
string_field: foo
36+
- index:
37+
_index: test_1
38+
_type: doc
39+
_id: 3
40+
- int_field: 101
41+
double_field: 101.0
42+
string_field: foo
43+
- index:
44+
_index: test_1
45+
_type: doc
46+
_id: 4
47+
- int_field: 151
48+
double_field: 151.0
49+
string_field: foo
50+
51+
---
52+
"Dots in agg names":
53+
54+
- skip:
55+
version: " - 6.3.99"
56+
reason: this feature was deprecated in 6.4.0
57+
features: "warnings"
58+
- do:
59+
warnings:
60+
- "Dots in aggregation names are deprecated and will be removed in 8.0"
61+
search:
62+
body:
63+
aggs:
64+
dots.in.agg.name:
65+
avg:
66+
field: int_field
67+
68+
- match: { hits.total: 4 }
69+
- length: { hits.hits: 4 }
70+
- match:
71+
aggregations:
72+
dots.in.agg.name:
73+
value: 76.0
74+
75+

server/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.elasticsearch.common.io.stream.StreamInput;
2424
import org.elasticsearch.common.io.stream.StreamOutput;
2525
import org.elasticsearch.common.io.stream.Writeable;
26+
import org.elasticsearch.common.logging.DeprecationLogger;
27+
import org.elasticsearch.common.logging.ESLoggerFactory;
2628
import org.elasticsearch.common.xcontent.ToXContentObject;
2729
import org.elasticsearch.common.xcontent.XContentBuilder;
2830
import org.elasticsearch.common.xcontent.XContentParser;
@@ -50,6 +52,7 @@
5052
import java.util.regex.Pattern;
5153

5254
public class AggregatorFactories {
55+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(ESLoggerFactory.getLogger("deprecation"));
5356
public static final Pattern VALID_AGG_NAME = Pattern.compile("[^\\[\\]>]+");
5457

5558
/**
@@ -75,6 +78,9 @@ private static AggregatorFactories.Builder parseAggregators(XContentParser parse
7578
throw new ParsingException(parser.getTokenLocation(), "Invalid aggregation name [" + aggregationName
7679
+ "]. Aggregation names must be alpha-numeric and can only contain '_' and '-'");
7780
}
81+
if (aggregationName.contains(".")) {
82+
deprecationLogger.deprecated("Dots in aggregation names are deprecated and will be removed in 8.0");
83+
}
7884

7985
token = parser.nextToken();
8086
if (token != XContentParser.Token.START_OBJECT) {

0 commit comments

Comments
 (0)