jobtech/jt-opensearch-support

Jobtech OpenSearch Support

1.0.4 2024-06-19 09:16 UTC

This package is auto-updated.

Last update: 2024-10-20 08:51:52 UTC


README

Jobtech OpenSearch Support

This package makes it easy to communicate with OpenSearch

Installation

Install the package in your application using composer

composer require jobtech/laravel-opensearch

Publish vendor

php artisan laravel-opensearch:install --tag="jt-opensearch-config"

This is the content of the published config file:

return [
    /*
    |--------------------------------------------------------------------------
    | Client config
    |--------------------------------------------------------------------------
    |
    | This is where client configurations are set up
    |
    */
    'client' => [
        'hosts' => [
            'host' => env('OPENSEARCH_HOST'),
        ],
        'basicAuthentication' => [env('OPENSEARCH_USER'), env('OPENSEARCH_SECRET')],
    ],

    /*
    |--------------------------------------------------------------------------
    | Indices config
    |--------------------------------------------------------------------------
    |
    | Put OpenSearch indices here
    |
    */
    'indices' => [],

    /*
    |--------------------------------------------------------------------------
    | Indices prefix
    |--------------------------------------------------------------------------
    |
    | Enter the OpenSearch prefix if you want indexes to have a specific prefix
    |
    */
    'prefix' => env('OPENSEARCH_PREFIX'),
];

Usage

Create own index that implements

\Jobtech\Support\OpenSearch\Contracts\Index

Declare in opensearch.php file your indices

'indices' => [
    //your index
],

Configure the connection parameters to OpenSearch, as host and basicAuthentication.

'client' => [
    'hosts' => [],
    'basicAuthentication' => [],
]

There is the possibility of adding a prefix to the indexes that are created with this package. The prefix is then handled automatically by the package.

'prefix' => [
    //your prefix
]

API

existsIndex

Returns whether or not an index already exists.

$bool = \Jobtech\Support\OpenSearch\Facades\IndexManager::existsIndex($index) // return OpenSearch response

getIndex

This operation returns information on an index.

$array = \Jobtech\Support\OpenSearch\Facades\IndexManager::getIndex($index) // return OpenSearch response

createIndex

An empty index can be created for later use. When creating an index, it is possible to specify its mappings, settings and aliases.

$array = \Jobtech\Support\OpenSearch\Facades\IndexManager::createIndex($index) // return OpenSearch response

putIndexSettings

Index-level settings can be updated. Dynamic index settings can be changed at any time, whereas static settings cannot be changed after the index has been created.

$array = \Jobtech\Support\OpenSearch\Facades\IndexManager::putIndexSettings($index) // return OpenSearch response

putIndexMappings

It is possible to create or add mappings and fields to an index. This operation cannot be used to update mappings that already correspond to existing data in the index.

$array = \Jobtech\Support\OpenSearch\Facades\IndexManager::putIndexMappings($index) // return OpenSearch response

deleteIndex

This operation delete an index.

$array = \Jobtech\Support\OpenSearch\Facades\IndexManager::deleteIndex($index) // return OpenSearch response

openIndex

A closed index can be opened, allowing data to be added or searched within the index.

$array = \Jobtech\Support\OpenSearch\Facades\IndexManager::openIndex($index) // return OpenSearch response

closeIndex

This operation closes an index. Once an index is closed, it is no longer possible to add data to it or search for data within the index.

$array = \Jobtech\Support\OpenSearch\Facades\IndexManager::closeIndex($index) // return OpenSearch response

retrieveDocument

This api permit to retrieve a document with information and data, from index with specified id.

$document = \Jobtech\Support\OpenSearch\Facades\DocumentManager::retrieveDocument('index', 'id') // return OpenSearch response

createDocument

It allows a document to be created with its data and a specific id.

$array = \Jobtech\Support\OpenSearch\Facades\DocumentManager::createDocument('index', 'id', ['']) // return OpenSearch response

createDocumentWithoutId

It allows a document to be created with its data and without a specific id.

$array = \Jobtech\Support\OpenSearch\Facades\DocumentManager::createDocumentWithoutId('index', ['']) // return OpenSearch response

createDocumentFrom

Allows you to create a document from an array of specific parameters.,

$array = \Jobtech\Support\OpenSearch\Facades\DocumentManager::createDocumentFrom([
    'index' => 'index',
    'id' => 'id',
    'body' => [''],
    'refresh' => true
]) // return OpenSearch response

updateDocument

It is possible to update the fields of a document in a specific index. Is it possible specify new data to be included in the index.

$array = \Jobtech\Support\OpenSearch\Facades\DocumentManager::updateDocument('index', 'id', ['']) // return OpenSearch response

upsertDocument

Upsert is an operation that conditionally either updates an existing document or inserts a new one based on information in the object.

$array = \Jobtech\Support\OpenSearch\Facades\DocumentManager::upsertDocument('index', 'id', ['']) // return OpenSearch response

deleteDocument

This operation delete a document.

$array = \Jobtech\Support\OpenSearch\Facades\DocumentManager::deleteDocument('index', 'id') // return OpenSearch response

countDocument

Returns how many document there are in the index.

$count = \Jobtech\Support\OpenSearch\Facades\DocumentManager::countDocument('index') // return OpenSearch response

search

Allows a search request to be made to search for data in the cluster according to the required parameters.

$search = \Jobtech\Support\OpenSearch\Facades\SearchManager::search('index') // return OpenSearch response

searchWithPagination

Allows a search request to be made to search for data in the cluster according to the required parameters. Everything is returned with a pagination.

$search = \Jobtech\Support\OpenSearch\Facades\SearchManager::searchWithPagination('index', 1, 10) // return OpenSearch response

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review SECURITY on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.