Skip to content

[Elasticsearch] Filtering on Nested Properties seems to not work #7997

Description

@Cocray

API Platform version(s) affected: 2.5.3

Description
When filtering on a nested property in ES, we must provide the nested path. Function getNestedFieldPath() in FieldDatatypeTrait.php seems to always return null.

With the example given in your documentation, if we try this filter: /tweets?author.gender=male

author is an object so we enter in this condition:

if (
Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()
&& null !== ($nextResourceClass = $type->getClassName())
&& $this->resourceClassResolver->isResourceClass($nextResourceClass)
) {
$nestedPath = $this->getNestedFieldPath($nextResourceClass, implode('.', $properties));
return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath";
}

getNestedFieldPath() is called recursively.

gender is the last element of the string, so when we do $currentProperty = array_shift($properties);, $properties is an empty array, so this part returns null:

if (!$properties) {
return null;
}

$nestedPath is null, so this line return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath"; returns null

This part seems to be never called:

if (
null !== ($type = $type->getCollectionValueType())
&& Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()
&& null !== ($className = $type->getClassName())
&& $this->resourceClassResolver->isResourceClass($className)
) {
return $currentProperty;
}

Thanks

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions