Skip to content

Fix exists query for flat object #17108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -506,20 +506,6 @@ teardown:

- length: { hits.hits: 2 }

# Exists Query with nested dot path, use the flat_object_field_name.last_key
- do:
search:
body: {
_source: true,
query: {
"exists": {
"field": issue.labels.type
}
}
}

- length: { hits.hits: 3 }

# Exists Query without dot path for the flat_object_field_name
- do:
search:
Expand Down Expand Up @@ -613,3 +599,22 @@ teardown:

- length: { hits.hits: 1 }
- match: { hits.hits.0._source.issue.labels.comment: [ [ "Doe","Shipped" ],[ "John","Approved" ] ] }

---
"Exists query for sub field":
- skip:
version: " - 2.99.99"
reason: "exists query for sub field of flat_object field has bug before 3.0.0"

- do:
search:
body: {
_source: true,
query: {
"exists": {
"field": issue.labels.category.type
}
}
}

- length: { hits.hits: 3 }
Original file line number Diff line number Diff line change
Expand Up @@ -506,23 +506,6 @@ teardown:

- length: { hits.hits: 2 }

# Exists Query with nested dot path, use the flat_object_field_name.last_key
- do:
search:
body: {
_source: true,
query: {
nested: {
path: "issue",
query: {
"exists": {
"field": issue.labels.type
} } }
}
}

- length: { hits.hits: 2 }

# Exists Query without dot path for the flat_object_field_name
- do:
search:
Expand Down Expand Up @@ -634,3 +617,27 @@ teardown:

- length: { hits.hits: 1 }
- match: { hits.hits.0._source.issue.0.labels.comment: [ [ "Doe","Shipped" ],[ "John","Approved" ] ] }

---
"Exists query for sub field":
- skip:
version: " - 2.99.99"
reason: "exists query for sub field of flat_object field has bug before 3.0.0"

- do:
search:
body: {
_source: true,
query: {
nested: {
path: "issue",
query: {
"exists": {
"field": issue.labels.category.type
}
}
}
}
}

- length: { hits.hits: 2 }
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ teardown:
body: {
_source: true,
query: {
exists: { "field": "record.d" }
exists: { "field": "record.name.d.name" }
},
sort: [{ order: asc}]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ public Query existsQuery(QueryShardContext context) {
String searchKey;
String searchField;
if (isSubField()) {
searchKey = this.rootFieldName;
searchField = name();
return rangeQuery(null, null, true, true, context);
} else {
if (hasDocValues()) {
return new FieldExistsQuery(name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,12 @@ public void testExistsQuery() {
ft.getValueFieldType(),
ft.getValueAndPathFieldType()
);
assertEquals(new TermQuery(new Term("field", "field.bar")), dynamicMappedFieldType.existsQuery(null));

Automaton termAutomaton = PrefixQuery.toAutomaton(new BytesRef("field.bar="));
Automaton dvAutomaton = PrefixQuery.toAutomaton(new BytesRef("field.field.bar="));
Query indexQuery = new AutomatonQuery(new Term("field" + VALUE_AND_PATH_SUFFIX), termAutomaton, true);
Query dvQuery = new AutomatonQuery(new Term("field" + VALUE_AND_PATH_SUFFIX), dvAutomaton, true, DOC_VALUES_REWRITE);
Query expected = new IndexOrDocValuesQuery(indexQuery, dvQuery);
assertEquals(expected, dynamicMappedFieldType.existsQuery(MOCK_QSC_ENABLE_INDEX_DOC_VALUES));
}

{
Expand Down Expand Up @@ -1176,8 +1180,8 @@ public void testRangeQuery() {
);
continue;
}
boolean nullLowerTerm = true;// randomBoolean();
boolean nullUpperTerm = true;// nullLowerTerm == false || randomBoolean();
boolean nullLowerTerm = randomBoolean();
boolean nullUpperTerm = nullLowerTerm == false || randomBoolean();

Automaton a1 = PrefixQuery.toAutomaton(new BytesRef("field.field1="));
Automaton a2 = TermRangeQuery.toAutomaton(
Expand Down
Loading