james.xue/laravel-elasticsearch

A Laravel Service Provider for the Elasticsearch API client

2.3.1 2022-08-04 05:23 UTC

README

Latest Stable Version Total Downloads Latest Unstable Version License

Install

composer require "james.xue/laravel-elasticsearch"

Publishing configuration

php artisan vendor:publish --tag=elasticsearch

Add env configuration

ELASTICSEARCH_CONNECTION=
ELASTICSEARCH_HOST=127.0.0.1
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_INDEX=
ELASTICSEARCH_TYPE=

Usage

$params = SearchBuilder::setKey(1)
    ->unsetBody()
    ->builder();
$params = search()->setKey(1)->unsetBody()->builder();

ElasticsearchClient::get($params);

// or

$params = SearchBuilder::connection("elastic1")
    ->setKey(1)
    ->unsetBody()
    ->builder();
$params = search("elastic1")->setKey(1)->unsetBody()->builder();

ElasticsearchClient::connection("elastic1")->get($params);

更多使用方法

laravel-elasticsearch-demo

License

MIT