A Symfony bundle providing native OpenSearch integration. Inspired by FOSElasticaBundle, built for OpenSearch from the ground up.
composer require bneumann/opensearch-bundle
Configure a client and an index:
# config/packages/opensearch.yaml
opensearch:
clients:
default:
hosts: ['https://localhost:9200']
username: '%env(OPENSEARCH_USER)%'
password: '%env(OPENSEARCH_PASS)%'
ssl_verification: true
indexes:
products:
index_name: 'products_%kernel.environment%'
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
name: { type: 'text' }
sku: { type: 'keyword' }
finder:
hydration: orm
persistence:
driver: orm
model: App\Entity\Product
provider: true
listener: true
identifier: id
Create and populate the index:
bin/console opensearch:index:create products
bin/console opensearch:index:populate products
Search using the finder service:
use Bneumann\OpensearchBundle\Finder\FinderInterface;
public function __construct(private FinderInterface $finder) {}
$results = $this->finder->find([
'query' => [
'match' => ['name' => 'bike'],
],
]);
Or use the repository pattern:
use Bneumann\OpensearchBundle\Repository\Repository;
final class ProductRepository extends Repository
{
public function findBySku(string $sku): iterable
{
return $this->search([
'query' => ['term' => ['sku' => $sku]],
]);
}
}
See CONTRIBUTING.md for guidelines.
This bundle is released under the MIT License.
How can I help you explore Laravel packages today?