Skip to content

Commit 37f19a5

Browse files
committed
revert <FilterPathBasedFilter support dot in field name> and move it into a new PR elastic#83178
1 parent e5a322a commit 37f19a5

File tree

6 files changed

+12
-96
lines changed

6 files changed

+12
-96
lines changed

libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentParserConfiguration.java

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,34 @@ public class XContentParserConfiguration {
3232
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
3333
RestApiVersion.current(),
3434
null,
35-
null,
36-
false
35+
null
3736
);
3837

3938
final NamedXContentRegistry registry;
4039
final DeprecationHandler deprecationHandler;
4140
final RestApiVersion restApiVersion;
4241
final FilterPath[] includes;
4342
final FilterPath[] excludes;
44-
final boolean supportDotInFieldName;
4543

4644
private XContentParserConfiguration(
4745
NamedXContentRegistry registry,
4846
DeprecationHandler deprecationHandler,
4947
RestApiVersion restApiVersion,
5048
FilterPath[] includes,
51-
FilterPath[] excludes,
52-
boolean supportDotInFieldName
49+
FilterPath[] excludes
5350
) {
5451
this.registry = registry;
5552
this.deprecationHandler = deprecationHandler;
5653
this.restApiVersion = restApiVersion;
5754
this.includes = includes;
5855
this.excludes = excludes;
59-
this.supportDotInFieldName = supportDotInFieldName;
6056
}
6157

6258
/**
6359
* Replace the registry backing {@link XContentParser#namedObject}.
6460
*/
6561
public XContentParserConfiguration withRegistry(NamedXContentRegistry registry) {
66-
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes, supportDotInFieldName);
62+
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes);
6763
}
6864

6965
public NamedXContentRegistry registry() {
@@ -75,7 +71,7 @@ public NamedXContentRegistry registry() {
7571
* a deprecated field.
7672
*/
7773
public XContentParserConfiguration withDeprecationHandler(DeprecationHandler deprecationHandler) {
78-
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes, supportDotInFieldName);
74+
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes);
7975
}
8076

8177
public DeprecationHandler deprecationHandler() {
@@ -87,7 +83,7 @@ public DeprecationHandler deprecationHandler() {
8783
* {@link RestApiVersion}.
8884
*/
8985
public XContentParserConfiguration withRestApiVersion(RestApiVersion restApiVersion) {
90-
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes, supportDotInFieldName);
86+
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes);
9187
}
9288

9389
public RestApiVersion restApiVersion() {
@@ -103,15 +99,10 @@ public XContentParserConfiguration withFiltering(Set<String> includeStrings, Set
10399
deprecationHandler,
104100
restApiVersion,
105101
FilterPath.compile(includeStrings),
106-
FilterPath.compile(excludeStrings),
107-
supportDotInFieldName
102+
FilterPath.compile(excludeStrings)
108103
);
109104
}
110105

111-
public XContentParserConfiguration withSupportDotInFieldName(boolean supportDotInFieldName) {
112-
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes, supportDotInFieldName);
113-
}
114-
115106
public JsonParser filter(JsonParser parser) {
116107
JsonParser filtered = parser;
117108
if (excludes != null) {
@@ -121,20 +112,10 @@ public JsonParser filter(JsonParser parser) {
121112
throw new UnsupportedOperationException("double wildcards are not supported in filtered excludes");
122113
}
123114
}
124-
filtered = new FilteringParserDelegate(
125-
filtered,
126-
new FilterPathBasedFilter(excludes, false).supportDotInFieldName(supportDotInFieldName),
127-
true,
128-
true
129-
);
115+
filtered = new FilteringParserDelegate(filtered, new FilterPathBasedFilter(excludes, false), true, true);
130116
}
131117
if (includes != null) {
132-
filtered = new FilteringParserDelegate(
133-
filtered,
134-
new FilterPathBasedFilter(includes, true).supportDotInFieldName(supportDotInFieldName),
135-
true,
136-
true
137-
);
118+
filtered = new FilteringParserDelegate(filtered, new FilterPathBasedFilter(includes, true), true, true);
138119
}
139120
return filtered;
140121
}

libs/x-content/src/main/java/org/elasticsearch/xcontent/support/filtering/FilterPath.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,6 @@ private boolean isFinalNode() {
7171
* @return true if the name equal a final node, otherwise return false
7272
*/
7373
boolean matches(String name, List<FilterPath> nextFilters) {
74-
return matches(name, nextFilters, false);
75-
}
76-
77-
/**
78-
* Similar to {@link #matches(String, List)}, but can set whether support dot in field name or not
79-
* @param name the xcontent property name
80-
* @param nextFilters nextFilters is a List, used to check the inner property of name
81-
* @param supportDotInFieldName support dot in field name or not
82-
* @return true if the name equal a final node, otherwise return false
83-
*/
84-
boolean matches(String name, List<FilterPath> nextFilters, boolean supportDotInFieldName) {
8574
if (nextFilters == null) {
8675
return false;
8776
}
@@ -110,23 +99,6 @@ boolean matches(String name, List<FilterPath> nextFilters, boolean supportDotInF
11099
nextFilters.add(this);
111100
}
112101

113-
// support dot in path
114-
if (supportDotInFieldName && nextFilters.isEmpty()) {
115-
// contains dot and not the first or last char
116-
int dotIndex = name.indexOf('.');
117-
if ((dotIndex != -1) && (dotIndex != 0) && (dotIndex != name.length() - 1)) {
118-
String prefixName = name.substring(0, dotIndex);
119-
String subName = name.substring(dotIndex + 1);
120-
termNode = termsChildren.get(prefixName);
121-
if (termNode != null) {
122-
if (termNode.isFinalNode) {
123-
return true;
124-
} else {
125-
return termNode.matches(subName, nextFilters, true);
126-
}
127-
}
128-
}
129-
}
130102
return false;
131103
}
132104

libs/x-content/src/main/java/org/elasticsearch/xcontent/support/filtering/FilterPathBasedFilter.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ public String toString() {
4242

4343
private final boolean inclusive;
4444

45-
private boolean supportDotInFieldName = false;
46-
47-
public FilterPathBasedFilter supportDotInFieldName(boolean supportDotInFieldName) {
48-
this.supportDotInFieldName = supportDotInFieldName;
49-
return this;
50-
}
51-
5245
public FilterPathBasedFilter(FilterPath[] filters, boolean inclusive) {
5346
if (filters == null || filters.length == 0) {
5447
throw new IllegalArgumentException("filters cannot be null or empty");
@@ -68,16 +61,14 @@ private TokenFilter evaluate(String name, FilterPath[] filterPaths) {
6861
if (filterPaths != null) {
6962
List<FilterPath> nextFilters = new ArrayList<>();
7063
for (FilterPath filter : filterPaths) {
71-
boolean matches = filter.matches(name, nextFilters, supportDotInFieldName);
64+
boolean matches = filter.matches(name, nextFilters);
7265
if (matches) {
7366
return MATCHING;
7467
}
7568
}
7669

7770
if (nextFilters.isEmpty() == false) {
78-
return new FilterPathBasedFilter(nextFilters.toArray(new FilterPath[nextFilters.size()]), inclusive).supportDotInFieldName(
79-
supportDotInFieldName
80-
);
71+
return new FilterPathBasedFilter(nextFilters.toArray(new FilterPath[nextFilters.size()]), inclusive);
8172
}
8273
}
8374
return NO_MATCHING;

libs/x-content/src/test/java/org/elasticsearch/xcontent/support/filtering/FilterPathTests.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -338,33 +338,4 @@ public void testNoMatchesFilter() {
338338
assertFalse(filterPath.matches(randomAlphaOfLength(10), nextFilters));
339339
assertEquals(nextFilters.size(), 0);
340340
}
341-
342-
public void testDotInFieldName() {
343-
// FilterPath match
344-
FilterPath[] filterPaths = FilterPath.compile(singleton("foo"));
345-
List<FilterPath> nextFilters = new ArrayList<>();
346-
assertTrue(filterPaths[0].matches("foo.bar", nextFilters, true));
347-
assertEquals(nextFilters.size(), 0);
348-
349-
// FilterPath not match
350-
filterPaths = FilterPath.compile(singleton("bar"));
351-
assertFalse(filterPaths[0].matches("foo.bar", nextFilters, true));
352-
assertEquals(nextFilters.size(), 0);
353-
354-
// FilterPath equals to fieldName
355-
filterPaths = FilterPath.compile(singleton("foo.bar"));
356-
assertTrue(filterPaths[0].matches("foo.bar", nextFilters, true));
357-
assertEquals(nextFilters.size(), 0);
358-
359-
// FilterPath longer than fieldName
360-
filterPaths = FilterPath.compile(singleton("foo.bar.test"));
361-
assertFalse(filterPaths[0].matches("foo.bar", nextFilters, true));
362-
assertEquals(nextFilters.size(), 1);
363-
nextFilters.clear();
364-
365-
// partial match
366-
filterPaths = FilterPath.compile(singleton("foo.bar.test"));
367-
assertFalse(filterPaths[0].matches("foo.bar.text", nextFilters, true));
368-
assertEquals(nextFilters.size(), 0);
369-
}
370341
}

server/src/main/java/org/elasticsearch/common/xcontent/XContentFieldFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static XContentFieldFilter newFieldFilter(String[] includes, String[] excludes)
7474
final XContentParserConfiguration parserConfig = XContentParserConfiguration.EMPTY.withFiltering(
7575
Set.of(includes),
7676
Set.of(excludes)
77-
).withSupportDotInFieldName(true);
77+
);
7878
return (originalSource, contentType) -> {
7979
if (originalSource == null || originalSource.length() <= 0) {
8080
if (contentType == null) {

server/src/test/java/org/elasticsearch/common/xcontent/support/XContentFiledFilterTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public void testIncludingObjectWithNestedIncludedObject() throws IOException {
243243
testFilter(actual, actual, singleton("*.obj2"), emptySet());
244244
}
245245

246+
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/83178")
246247
public void testDotsInFieldNames() throws IOException {
247248
Builder actual = builder -> builder.startObject()
248249
.field("foo.bar", 2)

0 commit comments

Comments
 (0)