An easy way to use the official PHP OpenSearch client in your Laravel applications.
shufo/laravel-opensearch is a Laravel package for an easy way to use the official php opensearch client in your laravel applications..
It currently has 5 GitHub stars and 8.820 downloads on Packagist (latest version v0.2.2).
Install it with composer require shufo/laravel-opensearch.
Discover more Laravel packages by shufo
or browse all Laravel packages to compare alternatives.
Last updated
:warning: This package is still in alpha. Don't use in production.
An easy way to use the official OpenSearch client in your Laravel applications.
This is the fork of laravel-elasticsearch.
Add repository to your composer.json
"repositories": [
{
"type": "vcs",
"url": "https://github.com/shufo/opensearch-php"
}
],
then
composer require shufo/laravel-opensearch
The package's service provider will automatically register its service provider.
Publish the configuration file:
php artisan vendor:publish --provider="Shufo\LaravelOpenSearch\ServiceProvider"
To change host of opensearch, set OPENSEARCH_HOST environment variable to your opensearch hostname.
To edit config you can edit config/opensearch.php.
$ vim config/opensearch.php
With Facade:
// search
>>> OpenSearch::search([
'index' => 'example',
'body' => [
'query' => [
'match' => [
'id' => '123'
]
]
]
])
=> [
"took" => 1,
"timed_out" => false,
"_shards" => [
"total" => 1,
"successful" => 1,
"skipped" => 0,
"failed" => 0,
],
"hits" => [
"total" => [
"value" => 1,
"relation" => "eq",
],
"max_score" => 0.6931471,
"hits" => [
[
"_index" => "example",
"_type" => "_doc",
"_id" => "1",
"_score" => 0.6931471,
"_source" => [
"id" => "123",
"body" => "test",
],
],
],
],
]
// create index
OpenSearch::indices()->create([
'index' => 'example',
'body' => [
'mappings' => [
'properties' => [
'id' => [
'type' => 'long',
],
'text' => [
'type' => 'text',
]
]
]
],
])
// add document to index
OpenSearch::index([
"id" => "123",
"body" => [
"id" => "123",
"text" => "foo",
],
"index" => "example",
]);
// delete index
OpenSearch::indices()->delete(['index' => 'example']);
// SQL (currently it's available only select operation)
>>> OpenSearch::sql()->query(["query" => "select * from example", "fetch_size" => 1])
=> [
"schema" => [
[
"name" => "body",
"type" => "text",
],
[
"name" => "id",
"type" => "keyword",
],
],
"cursor" => "d:eyJhIjp7fSwicyI6IkZHbHVZMngxWkdWZlkyOXVkR1Y0ZEY5MWRXbGtEWEYxWlhKNVFXNWtSbVYwWTJnQkZrTmZVamR0VEc1ZlUwSmxOM2h4U2w5bFRWQjRaMUVBQUFBQUFBQUFxaFpqUjFGckxVRm9YMUl6Vnpkc2NXaHlabkk1VFZGbiIsImMiOlt7Im5hbWUiOiJib2R5IiwidHlwZSI6InRleHQifSx7Im5hbWUiOiJpZCIsInR5cGUiOiJrZXl3b3JkIn1dLCJmIjoxLCJpIjoiZXhhbXBsZSIsImwiOjF9",
"total" => 2,
"datarows" => [
[
"test",
"123",
],
],
"size" => 1,
"status" => 200,
]
With Opensearch Client Builder:
use OpenSearch\ClientBuilder;
$data = [
'body' => [
'testField' => 'abc'
],
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
];
$client = ClientBuilder::create()->build();
$return = $client->index($data);
git checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)MIT