Skip to content

Commit 2a02446

Browse files
authored
Reject queries that act on nested fields or fields with nested field types in their hierarchy (#55721)
1 parent 400cfe2 commit 2a02446

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/analysis/AnalysisUtils.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,21 @@ else if (DataTypes.isUnsupported(fa.dataType())) {
8686
"Cannot use field [" + fa.name() + "] with unsupported type [" + unsupportedField.getOriginalType() + "]");
8787
}
8888
}
89-
// compound fields
90-
else if (allowCompound == false && DataTypes.isPrimitive(fa.dataType()) == false) {
89+
// compound fields that are not of "nested" type
90+
else if (allowCompound == false && DataTypes.isPrimitive(fa.dataType()) == false && fa.dataType() != DataTypes.NESTED) {
9191
named = u.withUnresolvedMessage(
9292
"Cannot use field [" + fa.name() + "] type [" + fa.dataType().typeName() + "] only its subfields");
9393
}
94+
// "nested" fields
95+
else if (fa.dataType() == DataTypes.NESTED) {
96+
named = u.withUnresolvedMessage("Cannot use field [" + fa.name() + "] type [" + fa.dataType().typeName() + "] "
97+
+ "due to nested fields not being supported yet");
98+
}
99+
// fields having nested parents
100+
else if (fa.isNested()) {
101+
named = u.withUnresolvedMessage("Cannot use field [" + fa.name() + "] type [" + fa.dataType().typeName() + "] "
102+
+ "with unsupported nested type in hierarchy (field [" + fa.nestedParent().name() +"])");
103+
}
94104
}
95105
return named;
96106
}

x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/querydsl/container/QueryContainer.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ private Tuple<QueryContainer, FieldExtraction> asFieldExtraction(Attribute attr)
9595

9696
if (expression instanceof FieldAttribute) {
9797
FieldAttribute fa = (FieldAttribute) expression;
98-
if (fa.isNested()) {
99-
throw new UnsupportedOperationException("Nested not yet supported");
100-
}
10198
return new Tuple<>(this, topHitFieldRef(fa));
10299
}
103100

x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/analysis/VerifierTests.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,13 @@ public void testObject() {
280280

281281
public void testNested() {
282282
final IndexResolution idxr = loadIndexResolution("mapping-nested.json");
283-
accept(idxr, "foo where processes.pid == 0");
284-
283+
assertEquals("1:11: Cannot use field [processes] type [nested] due to nested fields not being supported yet",
284+
error(idxr, "foo where processes == 0"));
285+
assertEquals("1:11: Cannot use field [processes.pid] type [long] with unsupported nested type in hierarchy (field [processes])",
286+
error(idxr, "foo where processes.pid == 0"));
285287
assertEquals("1:11: Unknown column [processe.pid], did you mean any of [processes.pid, processes.path, processes.path.keyword]?",
286288
error(idxr, "foo where processe.pid == 0"));
289+
accept(idxr, "foo where long_field == 123");
287290
}
288291

289292
public void testGeo() {
@@ -314,20 +317,24 @@ public void testMultiField() {
314317

315318
accept(idxr, "foo where multi_field_options.raw == 'bar'");
316319
accept(idxr, "foo where multi_field_options.key == 'bar'");
317-
318320
accept(idxr, "foo where multi_field_ambiguous.one == 'bar'");
319321
accept(idxr, "foo where multi_field_ambiguous.two == 'bar'");
322+
320323
assertEquals("1:11: [multi_field_ambiguous.normalized == 'bar'] cannot operate on first argument field of data type [keyword]: " +
321324
"Normalized keyword field cannot be used for exact match operations",
322325
error(idxr, "foo where multi_field_ambiguous.normalized == 'bar'"));
323-
324-
assertEquals("1:11: [multi_field_nested.dep_name == 'bar'] cannot operate on first argument field of data type [text]: " +
325-
"No keyword/multi-field defined exact matches for [dep_name]; define one or use MATCH/QUERY instead",
326+
assertEquals("1:11: Cannot use field [multi_field_nested.dep_name] type [text] with unsupported nested type in hierarchy " +
327+
"(field [multi_field_nested])",
326328
error(idxr, "foo where multi_field_nested.dep_name == 'bar'"));
327-
328-
accept(idxr, "foo where multi_field_nested.dep_id.keyword == 'bar'");
329-
accept(idxr, "foo where multi_field_nested.end_date == ''");
330-
accept(idxr, "foo where multi_field_nested.start_date == 'bar'");
329+
assertEquals("1:11: Cannot use field [multi_field_nested.dep_id.keyword] type [keyword] with unsupported nested type in " +
330+
"hierarchy (field [multi_field_nested])",
331+
error(idxr, "foo where multi_field_nested.dep_id.keyword == 'bar'"));
332+
assertEquals("1:11: Cannot use field [multi_field_nested.end_date] type [datetime] with unsupported nested type in " +
333+
"hierarchy (field [multi_field_nested])",
334+
error(idxr, "foo where multi_field_nested.end_date == ''"));
335+
assertEquals("1:11: Cannot use field [multi_field_nested.start_date] type [datetime] with unsupported nested type in " +
336+
"hierarchy (field [multi_field_nested])",
337+
error(idxr, "foo where multi_field_nested.start_date == 'bar'"));
331338
}
332339

333340
public void testStringFunctionWithText() {

x-pack/plugin/eql/src/test/resources/mapping-nested.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
}
2626
}
2727
}
28+
},
29+
"long_field" : {
30+
"type" : "long"
2831
}
2932
}
3033
}

0 commit comments

Comments
 (0)