I use FOS Elastica bundle in my Symfony application but I am not using Doctrine. I try to populate the Elasticsearch with a custom provider. Here is my code.
# config/packages/fos_elastica.yaml
fos_elastica:
clients:
default: { url: '%env(ELASTICSEARCH_URL)%' }
indexes:
my_index:
use_alias: true
properties:
my_property:
type: keyword
persistence:
provider:
service: app.search_provider.my_provider
listener: false
# config/services.yaml
services:
# ...
app.search_provider.my_provider:
class: App\SearchProvider\MyProvider
tags:
- { name: fos_elastica.pager_provider, index: my_index, type: my_type }
<?php
// src/SearchProvider/MyProvider.php
namespace App\SearchProvider;
use Elastica\Document;
use FOS\ElasticaBundle\Provider\PagerfantaPager;
use FOS\ElasticaBundle\Provider\PagerInterface;
use FOS\ElasticaBundle\Provider\PagerProviderInterface;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
final class MyProvider implements PagerProviderInterface
{
public function provide(array $options = []): PagerInterface
{
$document = new Document();
$document->setData([
'my_property' => 'test',
]);
return new PagerfantaPager(new Pagerfanta(new ArrayAdapter([$document])));
}
}
When I use the command bin/console fos:elastica:populate
I get the following error
FOS\ElasticaBundle\Persister\ObjectPersister::__construct(): Argument #3 ($objectClass) must be of type string, null given
Also I am wondering how I can index a great number of documents. I think they would be too much to store in an array. Is there a way to use a callback instead of an array in new Pagerfanta
or something like that?