jobtech/jt-opensearch-support

Jobtech OpenSearch 支持

1.0.4 2024-06-19 09:16 UTC

This package is auto-updated.

Last update: 2024-09-20 08:38:25 UTC


README

Jobtech OpenSearch 支持

此包可以轻松与 OpenSearch 通信

安装

使用 composer 在您的应用程序中安装此包

composer require jobtech/laravel-opensearch

发布供应商

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

这是发布配置文件的内容

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'),
];

用法

创建自己的索引实现

\Jobtech\Support\OpenSearch\Contracts\Index

在 opensearch.php 文件中声明您的索引

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

配置 OpenSearch 的连接参数,如主机和基本身份验证。

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

此包可以添加一个前缀到创建的索引。然后,包将自动处理该前缀。

'prefix' => [
    //your prefix
]

API

existsIndex

返回索引是否存在。

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

getIndex

此操作返回有关索引的信息。

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

createIndex

可以创建一个空的索引供以后使用。在创建索引时,可以指定其映射、设置和别名。

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

putIndexSettings

可以更新索引级别的设置。动态索引设置可以在任何时间更改,而静态设置在索引创建后不能更改。

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

putIndexMappings

可以在索引中创建或添加映射和字段。此操作不能用于更新与索引中现有数据对应的映射。

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

deleteIndex

此操作删除索引。

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

openIndex

可以打开一个关闭的索引,允许向索引中添加数据或搜索索引中的数据。

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

closeIndex

此操作关闭索引。一旦索引被关闭,就无法再向其中添加数据或搜索数据。

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

retrieveDocument

此 API 允许从具有指定 id 的索引中检索包含信息和数据的文档。

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

createDocument

它允许创建具有其数据和特定 id 的文档。

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

createDocumentWithoutId

它允许创建具有其数据但没有特定 id 的文档。

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

createDocumentFrom

允许您从一组特定参数创建文档。

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

updateDocument

可以更新特定索引中文档的字段。可以指定要包含在索引中的新数据。

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

upsertDocument

Upsert 是一个条件操作,根据对象中的信息,要么更新现有文档,要么插入新文档。

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

deleteDocument

此操作删除文档。

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

countDocument

返回索引中有多少个文档。

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

search

允许根据所需参数在集群中搜索数据。

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

searchWithPagination

允许根据所需参数在集群中搜索数据。所有内容都带有分页返回。

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

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献

安全漏洞

有关报告安全漏洞的详细信息,请参阅安全

鸣谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅许可文件