Skip to content

Commit

Permalink
add console commands
Browse files Browse the repository at this point in the history
  • Loading branch information
basemkhirat committed Feb 24, 2017
1 parent e70817b commit 18af52d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 8 deletions.
93 changes: 91 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
## Laravel, Lumen and Native php elasticseach query builder to build complex queries using an elegant syntax

- Keeps you away from wasting your time by replacing array queries with a simple and elegant syntax you will love.
- Feeling free to create, drop and mapping index fields throw easy artisan console commands.
- Lumen framework support.
- Native php and composer based applications support.
- Supports [laravel 5.4](https://laravel.com/docs/5.4) and can be used as a [laravel scout](https://laravel.com/docs/5.4/scout) driver.
- Dealing with multiple elasticsearch connections at the same time.
- Supports scan and scroll queries for dealing big data.
- Awesome pagination based on [LengthAwarePagination](https://github.com/illuminate/pagination).
- Feeling free to create, drop and mapping index fields.

- Caching queries using a caching layer over query builder built on [laravel cache](https://laravel.com/docs/5.4/cache).

## Requirements
Expand Down Expand Up @@ -124,9 +125,13 @@ $documents = $connection->search("hello")->get();
- `config/es.php` where you can add more than one elasticsearch server.

```
# Here you can define the default connection name.
'default' => env('ELASTIC_CONNECTION', 'default'),
# Here you can define your connections.
'connections' => [
'default' => [
'servers' => [
Expand All @@ -141,12 +146,96 @@ $documents = $connection->search("hello")->get();
'index' => env('ELASTIC_INDEX', 'my_index'),
'type' => env('ELASTIC_TYPE', 'my_type'),
]
]
],
# Here you can define your indices.
'indices' => [
'my_index' => [
'settings' => [
"number_of_shards" => 1,
"number_of_replicas" => 0,
],
'mappings' => [
'posts' => [
'title' => [
'type' => 'string'
]
]
]
]
]
```

- `config/scout.php` where you can use package as a laravel scout driver.

## Working with console environment

With some artisan commands you can do some tasks such as creating or updating settings or mappings.

Note that all commands are running with `--connection=default` option, you can change it throw the command.

These are all available commands:

##### List All indices on server.

```
php artisan es:indices
+--------+--------+----------+------------------------+-----+-----+------------+--------------+------------+----------------+
| health | status | index | uuid | pri | rep | docs.count | docs.deleted | store.size | pri.store.size |
+--------+--------+----------+------------------------+-----+-----+------------+--------------+------------+----------------+
| green | open | my_index | 5URW60KJQNionAJgL6Q2TQ | 1 | 0 | 0 | 0 | 260b | 260b |
+--------+--------+----------+------------------------+-----+-----+------------+--------------+------------+----------------+
```

##### Create a new index using defined settings and mapping in `es.php` config file.

```
# Create all indices in config file.
php artisan es:index:create
# Create only 'my_index' index in config file
php artisan es:index:create my_index
```

##### Update index using defined settings and mapping in `es.php` config file.

```
# Update all indices in config file.
php artisan es:index:update
# Update only 'my_index' index in config file
php artisan es:index:update my_index
```

##### Drop index.

Running Drop command with `--force` option will skip all confirmation messages.

```
# Drop all indices in config file.
php artisan es:index:drop
# Drop specific index on sever. Not matter to be in config file.
php artisan es:index:drop my_index
```





## Usage as a Laravel Scout driver

First, follow [Laravel Scout installation](https://laravel.com/docs/5.4/scout#installation).
Expand Down
11 changes: 5 additions & 6 deletions src/ElasticsearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

namespace Basemkhirat\Elasticsearch;

use Basemkhirat\Elasticsearch\Commands\CreateIndexCommand;
use Basemkhirat\Elasticsearch\Commands\DropIndexCommand;
use Basemkhirat\Elasticsearch\Commands\UpdateIndexCommand;
use Elasticsearch\ClientBuilder as ElasticBuilder;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\ServiceProvider;
use Laravel\Scout\EngineManager;
use Basemkhirat\Elasticsearch\Commands\ListIndicesCommand;
use Basemkhirat\Elasticsearch\Commands\CreateIndexCommand;
use Basemkhirat\Elasticsearch\Commands\DropIndexCommand;
use Basemkhirat\Elasticsearch\Commands\UpdateIndexCommand;

class ElasticsearchServiceProvider extends ServiceProvider
{

function __construct()
{
$this->path = dirname(__FILE__);
$this->app = app();
}

Expand All @@ -29,11 +28,11 @@ public function boot()
{

$this->mergeConfigFrom(
$this->path . '/config/es.php', 'es'
dirname(__FILE__) . '/config/es.php', 'es'
);

$this->publishes([
$this->path . '/config/' => config_path(),
dirname(__FILE__) . '/config/' => config_path(),
], "es.config");

// Auto configuration with lumen framework.
Expand Down

0 comments on commit 18af52d

Please sign in to comment.