api-platform / api-platform/core

[Elasticsearch] Filtering on Nested Properties seems to not work

未關閉
#7,997 4 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視
Elasticsearch
主要語言
PHP
星號
2.6k
分支
980
平均合併
2 天 5 小時
30 天內合併 PR
48

描述

**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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。