Skip to content

feat(elasticsearch): filtering on nested fields - #5820

Merged
soyuka merged 3 commits into
api-platform:mainfrom
jonnyeom:fix-nested-fields-3.1
Sep 14, 2023
Merged

feat(elasticsearch): filtering on nested fields#5820
soyuka merged 3 commits into
api-platform:mainfrom
jonnyeom:fix-nested-fields-3.1

Conversation

@jonnyeom

Copy link
Copy Markdown
Contributor

This is a resurrection of #5643

QA
Branch?main
Tickets#7997 and #5642
LicenseMIT
Doc PRWIP

This PR implements the following changes to support filtering on paths like foo.bar.baz:

  1. If foo is an object, isNestedField() now returns true instead of false
  2. If foo is an object, getNestedFieldPath() now returns "foo.bar" instead of null
  3. If foo is a collection, getNestedFieldPath() now returns "foo.bar" instead of just "foo" (matching the behavior if foo is an object)

As a result, filtering on deeply-nested paths (with 3 or more levels) now produces the following query:

 {
"nested": {
- "path": "foo",+ "path": "foo.bar",
"query": {
"term": {"foo.bar.baz": "qux"}
}
}
}
}

@soyukasoyuka changed the title feat(elasticsearch): Add filtering on nested fieldsfeat(elasticsearch): filtering on nested fieldsSep 14, 2023
@soyuka
soyuka merged commit d85884d into api-platform:mainSep 14, 2023
@soyuka

Copy link
Copy Markdown
Member

Thanks @jonnyeom

@jonnyeom
jonnyeom deleted the fix-nested-fields-3.1 branch September 14, 2023 14:41
@soyuka

Copy link
Copy Markdown
Member

I think that this actually breaks elasticsearch test suite my bad.

$nestedPath = $this->getNestedFieldPath($nextResourceClass, implode('.', $properties));

return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath";
return null === $nestedPath ? $currentProperty : "$currentProperty.$nestedPath";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting.
Let me take a deeper look again.

Thanks for heads up!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jonnyeom@soyuka@colinodell