Skip to content

feat(elasticsearch): filtering on nested fields #5820

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 3 commits into from
Sep 14, 2023

Conversation

jonnyeom
Copy link
Contributor

This is a resurrection of #5643

Q A
Branch? main
Tickets api-platform/api-platform#1375 and #5642
License MIT
Doc PR WIP

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"}
            }
         }
     }
 }

@jonnyeom jonnyeom force-pushed the fix-nested-fields-3.1 branch from 80af82e to da31df4 Compare September 13, 2023 21:24
@soyuka soyuka changed the title feat(elasticsearch): Add filtering on nested fields feat(elasticsearch): filtering on nested fields Sep 14, 2023
@soyuka soyuka merged commit d85884d into api-platform:main Sep 14, 2023
@soyuka
Copy link
Member

soyuka commented Sep 14, 2023

Thanks @jonnyeom

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

soyuka commented Sep 15, 2023

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

@@ -69,7 +69,7 @@ private function getNestedFieldPath(string $resourceClass, string $property): ?s
) {
$nestedPath = $this->getNestedFieldPath($nextResourceClass, implode('.', $properties));

return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath";
return null === $nestedPath ? $currentProperty : "$currentProperty.$nestedPath";
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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 free to 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