How implement Elasticsearch in cget
See original GitHub issueHi @Dunglas,
I’ve read somewhere that you use frequently Elasticsearch with api-platform.
I tried to serialize my $finder->findPaginated($query)
result as the same format as the cget result (in jsonld).
[EDIT] I don’t want to just returns IDs because I want to send my aggregations to the front too. I want to do this way because it let me build my search dynamically in front with the result of the cget).
I don’t know how to implement my searcher services in cget action and disable the filters. I just want to give my result for serializing.
Might you please provide an example of the way you do to implement ES in your ApiPlatform projects. I don’t understand if I should make a customFilter (which seem to only provide a query builder to api platform) that completely overrides the filter feature provided with ApiPlatform.
Thanks a lot,
Ksom
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Unfortunately, it’s not possible to add a “buckets” column in hydra mapping via a filter because the ApiPlatform\Core\Hydra\Serializer\CollectionFiltersNormalizer is restrictive (at least on api-platform version from 2.1 to 2.3) :
Currently, the only way to achieve the aggregation normalization, is to put this information in the property column of the description of your custom filter. Perhaps it would be fine to authorize the extension of hydra mapping information via CustomFilters to make work what @ksom wrote last year.
The method getSearch of ApiPlatform\Core\Hydra\Serializer\CollectionFiltersNormalizer could be something like this:
What do you think about it ?
Hi @Simperfit,
I have one SearcherService:
I have one custom provider ElasticsearchCollectionDataProvider:
I have an ElasticsearchFilter:
To resume: I have a searcher, a custom filter and a custom provider. The searcher save results and aggregations in cached properties. I call the SearcherService#search() method in a custom Provider (because providers are called before filters) and I return the SearcherService#getResults method. In the custom Filter I override getDescription method to foreach over SearcherService#getAggregations() to add a buckets key in the description for each aggregation.
I can’t give you a complete example at this moment. I’m sorry to answer you just now but I’m really busy actually.
If you have any questions related to this post please let me know I will do my best to answer you quickly.
Hope this can help!