# lumen-elasticsearch **Repository Path**: tao_bao/lumen-elasticsearch ## Basic Information - **Project Name**: lumen-elasticsearch - **Description**: lumen集成elasticsearch框架 - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-10-15 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # lumen-elasticsearch 以我开发的zero/lumen-elasticsearch包为例 1、创建开发包文件E:\www\project\packages 注意这里的packages这个文件名可以自定义但是一定要和app目录同级 . ├── apidoc.json ├── app ├── artisan ├── bootstrap ├── composer.json ├── composer.lock ├── composer.phar ├── config ├── database ├── _ide_helper.php ├── package.json ├── packages ├── phpunit.xml ├── public ├── README.md ├── resources ├── storage ├── tests └── vendor 2、创建开发包文件结构E:\www\project\packages\zero\lumen-elasticsearch\src cd /www/project/packages mkdir -p zero/lumen-elasticsearch/src 3.初始化composer.json文件会有一些提示,按需要填写 cd /www/project/packages/zero/lumen-elasticsearch composer init 文件结构如下: ├── composer.json └── src 4.修改E:\www\project\composer.json文件 "autoload": { "psr-4": { "App\\": "app/", "Zero\\LumenElasticsearch\\": "packages/zero/lumen-elasticsearch/src" } }, 5.在E:\www\project\packages\zero\lumen-elasticsearch\src下创建文件 结构如下: ├── composer.json └── src ├── Facade.php ├── Factory.php ├── LumenManager.php └── LumenServiceProvider.php 6.在E:\www\project\bootstrap\app.php 注册服务 //引入elasticsearch $app->register(Zero\LumenElasticsearch\LumenServiceProvider::class); //class_alias('Cviebrock\LaravelElasticsearch\Facade', 'Elasticsearch'); $app->configure('elasticsearch');//必须配置否则会报错 7.在自己对应的本地环境设置配置文件,我本地就是 E:\www\project\config\develop\elasticsearch.php 'default', /** * These are the connection parameters used when building a client. */ 'connections' => [ 'default' => [ /** * Hosts * * This is an array of hosts that the client will connect to. It can be a * single host, or an array if you are running a cluster of Elasticsearch * instances. * * This is the only configuration value that is mandatory. * * Presently using "extended" host configuration method * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_extended_host_configuration * * There is also the shorter "inline" configuration method available * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_inline_host_configuration */ 'hosts' => [ [ 'host' => env('ELASTICSEARCH_HOST', 'localhost'), 'port' => env('ELASTICSEARCH_PORT', 9200), 'scheme' => env('ELASTICSEARCH_SCHEME', null), 'user' => env('ELASTICSEARCH_USER', null), 'pass' => env('ELASTICSEARCH_PASS', null), ], ], /** * SSL * * If your Elasticsearch instance uses an out-dated or self-signed SSL * certificate, you will need to pass in the certificate bundle. This can * either be the path to the certificate file (for self-signed certs), or a * package like https://github.com/Kdyby/CurlCaBundle. See the documentation * below for all the details. * * If you are using SSL instances, and the certificates are up-to-date and * signed by a public certificate authority, then you can leave this null and * just use "https" in the host path(s) above and you should be fine. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_security.html#_ssl_encryption_2 */ 'sslVerification' => null, /** * Logging * * Logging is handled by passing in an instance of Monolog\Logger (which * coincidentally is what Laravel's default logger is). * * If logging is enabled, you either need to set the path and log level * (some defaults are given for you below), or you can use a custom logger by * setting 'logObject' to an instance of Psr\Log\LoggerInterface. In fact, * if you just want to use the default Laravel logger, then set 'logObject' * to \Log::getMonolog(). * * Note: 'logObject' takes precedent over 'logPath'/'logLevel', so set * 'logObject' null if you just want file-based logging to a custom path. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#enabling_logger */ 'logging' => false, // If you have an existing instance of Monolog you can use it here. // 'logObject' => \Log::getMonolog(), 'logPath' => storage_path('logs/elasticsearch.log'), 'logLevel' => Monolog\Logger::INFO, /** * Retries * * By default, the client will retry n times, where n = number of nodes in * your cluster. If you would like to disable retries, or change the number, * you can do so here. * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_set_retries */ 'retries' => null, /** * The remainder of the configuration options can almost always be left * as-is unless you have specific reasons to change them. Refer to the * appropriate sections in the Elasticsearch documentation for what each option * does and what values it expects. */ /** * Sniff On Start * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html */ 'sniffOnStart' => false, /** * HTTP Handler * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_configure_the_http_handler * @see http://ringphp.readthedocs.org/en/latest/client_handlers.html */ 'httpHandler' => null, /** * Connection Pool * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_the_connection_pool * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_connection_pool.html */ 'connectionPool' => null, /** * Connection Selector * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_the_connection_selector * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_selectors.html */ 'connectionSelector' => null, /** * Serializer * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_the_serializer * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_serializers.html */ 'serializer' => null, /** * Connection Factory * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_a_custom_connectionfactory */ 'connectionFactory' => null, /** * Endpoint * * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_set_the_endpoint_closure */ 'endpoint' => null, ], ], ]; 8.在E:\www\project目录下执行,重新生成自动加载文件配置 composer dump-autoload 9.注意:我使用的是lumen框架