diff --git a/.scrutinizer.yml b/.scrutinizer.yml
index bdab40f..4e34d94 100644
--- a/.scrutinizer.yml
+++ b/.scrutinizer.yml
@@ -1,13 +1,6 @@
build:
nodes:
coverage:
- services:
- elasticsearch: 6.4.0
-
- environment:
- variables:
- ELASTICSEARCH_PORT: 9200
-
cache:
directories:
- vendor/
diff --git a/README.md b/README.md
index 4d0ac36..d88fd77 100644
--- a/README.md
+++ b/README.md
@@ -13,9 +13,10 @@
[![Latest development][ico-version-dev]][link-packagist]
[![Monthly installs][ico-downloads-monthly]][link-downloads]
-A service provider for laravel to managing data versions in elasticsearch.
+A laravel service provider for the elasticsearch php client: https://github.com/elastic/elasticsearch-php
## Supported laravel versions
+[![Laravel 5.6][icon-l55]][link-laravel]
[![Laravel 5.6][icon-l56]][link-laravel]
[![Laravel 5.7][icon-l57]][link-laravel]
@@ -26,11 +27,6 @@ A service provider for laravel to managing data versions in elasticsearch.
[![Elasticsearch 6.3][icon-e63]][link-elasticsearch]
[![Elasticsearch 6.4][icon-e64]][link-elasticsearch]
-## Main features
-- Migration
-- Versioning
-- Deploy
-
## Installation
### Composer
@@ -63,8 +59,7 @@ If you do find an issue, please feel free to report it with GitHub's bug tracker
Alternatively, fork the project and make a pull request. :)
## Testing
-1. docker-compose up
-2. ./vendor/phpunit/phpunit/phpunit
+>composer test
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
@@ -95,6 +90,7 @@ The code for LaravelElasticsearchProvider is distributed under the terms of the
[link-downloads]: https://packagist.org/packages/triadev/laravel-elasticsearch-provider/stats
[link-travis]: https://travis-ci.org/triadev/LaravelElasticsearchProvider
+[icon-l55]: https://img.shields.io/badge/Laravel-5.5-brightgreen.svg?style=flat-square
[icon-l56]: https://img.shields.io/badge/Laravel-5.6-brightgreen.svg?style=flat-square
[icon-l57]: https://img.shields.io/badge/Laravel-5.7-brightgreen.svg?style=flat-square
diff --git a/composer.json b/composer.json
index 7be45c6..271a92c 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"name": "triadev/laravel-elasticsearch-provider",
- "description": "A service provider for laravel to managing data versions in elasticsearch.",
+ "description": "A laravel service provider for the elasticsearch php client.",
"keywords": ["Elasticsearch", "Laravel", "Lumen"],
"license": "MIT",
"authors": [
@@ -12,8 +12,7 @@
"require": {
"php": ">=7.1",
"laravel/framework": "5.5.* || 5.6.* || 5.7.*",
- "elasticsearch/elasticsearch": "^6.0",
- "triadev/laravel-prometheus-exporter": "^1.3"
+ "elasticsearch/elasticsearch": "^6.0"
},
"require-dev": {
"phpunit/phpunit": "~7.0",
diff --git a/docker-compose.yml b/docker-compose.yml
deleted file mode 100644
index c662455..0000000
--- a/docker-compose.yml
+++ /dev/null
@@ -1,42 +0,0 @@
-version: '2.2'
-services:
- elasticsearch:
- image: docker.elastic.co/elasticsearch/elasticsearch:6.4.0
- container_name: elasticsearch
- environment:
- - cluster.name=test-cluster
- - bootstrap.memory_lock=true
- - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- ulimits:
- memlock:
- soft: -1
- hard: -1
- volumes:
- - esdata1:/usr/share/elasticsearch/data
- ports:
- - 9200:9200
-
- elasticsearch2:
- image: docker.elastic.co/elasticsearch/elasticsearch:6.4.0
- container_name: elasticsearch2
- environment:
- - cluster.name=test-cluster
- - bootstrap.memory_lock=true
- - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- - "discovery.zen.ping.unicast.hosts=elasticsearch"
- ulimits:
- memlock:
- soft: -1
- hard: -1
- volumes:
- - esdata2:/usr/share/elasticsearch/data
-
-volumes:
- esdata1:
- driver: local
- esdata2:
- driver: local
-
-networks:
- default:
- driver: bridge
diff --git a/phpunit.xml b/phpunit.xml
index 08ffb7c..34f65a6 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -15,9 +15,6 @@
./src
-
- ./src/Models
-
diff --git a/src/Business/AbstractElasticsearch.php b/src/Business/AbstractElasticsearch.php
deleted file mode 100644
index c2e6b13..0000000
--- a/src/Business/AbstractElasticsearch.php
+++ /dev/null
@@ -1,48 +0,0 @@
-elasticsearchClient) {
- $this->elasticsearchClient = $this->buildElasticsearchClient();
- }
-
- return $this->elasticsearchClient;
- }
-
- private function buildElasticsearchClient() : Client
- {
- $clientBuilder = ClientBuilder::create();
- $clientBuilder->setHosts([
- [
- 'host' => $this->getHost(),
- 'port' => $this->getPort(),
- 'scheme' => $this->getScheme(),
- 'user' => $this->getUser(),
- 'pass' => $this->getPassword()
- ]
- ]);
-
- $clientBuilder->setRetries($this->getRetries());
-
- return $clientBuilder->build();
- }
-}
diff --git a/src/Business/Config/ConfigFacade.php b/src/Business/Config/ConfigFacade.php
deleted file mode 100644
index db1613c..0000000
--- a/src/Business/Config/ConfigFacade.php
+++ /dev/null
@@ -1,82 +0,0 @@
-getConfig()['host'];
- }
-
- /**
- * @return int
- */
- public function getPort() : int
- {
- return $this->getConfig()['port'];
- }
-
- /**
- * @return string
- */
- public function getScheme() : string
- {
- return $this->getConfig()['scheme'];
- }
-
- /**
- * @return string
- */
- public function getUser() : string
- {
- return $this->getConfig()['user'];
- }
-
- /**
- * @return string
- */
- public function getPassword() : string
- {
- return $this->getConfig()['pass'];
- }
-
- /**
- * @return int
- */
- public function getRetries() : int
- {
- return $this->getConfig()['config']['retries'];
- }
-
- /**
- * @return array
- */
- public function getIndices() : array
- {
- return $this->getConfig()['config']['indices'];
- }
-
- /**
- * @return array
- */
- public function getDeployVersions() : array
- {
- return $this->getConfig()['deploy']['version'];
- }
-
- /**
- * @return array
- */
- public function getSnapshot() : array
- {
- return $this->getConfig()['snapshot'];
- }
-
- private function getConfig() : array
- {
- return config('triadev-elasticsearch');
- }
-}
diff --git a/src/Business/Helper/Version.php b/src/Business/Helper/Version.php
deleted file mode 100644
index ba9e37c..0000000
--- a/src/Business/Helper/Version.php
+++ /dev/null
@@ -1,21 +0,0 @@
- env('ELASTICSEARCH_PORT', 9200),
'scheme' => env('ELASTICSEARCH_SCHEME', 'https'),
'user' => env('ELASTICSEARCH_USER', ''),
- 'pass' => env('ELASTICSEARCH_PASS', ''),
- 'deploy' => [
- 'version' => [
- 'indices' => []
- ]
- ],
- 'snapshot' => [
- 'repository' => 'default',
- 'type' => 'gcs',
- 'settings' => []
- ],
- 'config' => [
- 'retries' => 2,
- 'indices' => []
- ]
+ 'pass' => env('ELASTICSEARCH_PASS', '')
];
diff --git a/src/Console/Commands/Alias/Create.php b/src/Console/Commands/Alias/Create.php
deleted file mode 100644
index 1bc04fe..0000000
--- a/src/Console/Commands/Alias/Create.php
+++ /dev/null
@@ -1,60 +0,0 @@
-argument('index');
- $alias = (string)$this->argument('alias');
- $version = (string)$this->argument('version');
-
- Log::info("The alias is created.", [
- 'index' => $index,
- 'alias' => $alias,
- 'version' => $version
- ]);
-
- try {
- $elasticsearchAlias->addAlias($index, $alias, $version);
-
- Log::info("The alias was created.", [
- 'index' => $index,
- 'alias' => $alias,
- 'version' => $version
- ]);
- } catch (\Throwable $e) {
- Log::error($e->getMessage(), [
- 'index' => $index,
- 'alias' => $alias,
- 'version' => $version
- ]);
- }
- }
-}
diff --git a/src/Console/Commands/Alias/Delete.php b/src/Console/Commands/Alias/Delete.php
deleted file mode 100644
index 8dc2848..0000000
--- a/src/Console/Commands/Alias/Delete.php
+++ /dev/null
@@ -1,67 +0,0 @@
-argument('index');
- $alias = $this->argument('alias');
- $version = $this->argument('version');
-
- Log::info(sprintf(
- "The alias is deleted: %s | %s | %s",
- $index,
- $alias,
- $version
- ));
-
- try {
- $elasticsearchAlias->deleteAlias($index, $alias, $version);
-
- Log::info(sprintf(
- "The alias was deleted: %s | %s | %s",
- $index,
- $alias,
- $version
- ));
- } catch (AliasNotFoundException $e) {
- Log::error($e->getMessage());
- } catch (\Exception $e) {
- Log::error(sprintf(
- "The alias was not deleted: %s | %s | %s | %s",
- $index,
- $alias,
- $version,
- $e->getMessage()
- ));
- }
- }
-}
diff --git a/src/Console/Commands/Index/Create.php b/src/Console/Commands/Index/Create.php
deleted file mode 100644
index 369b6f0..0000000
--- a/src/Console/Commands/Index/Create.php
+++ /dev/null
@@ -1,73 +0,0 @@
-argument('version');
-
- $indices = $this->getIndices();
-
- if ($this->argument('index') == '_all') {
- $index = array_keys($indices);
- } else {
- $index = explode(',', $this->argument('index'));
- }
-
- foreach ($index as $i) {
- if (!array_key_exists($i, $indices)) {
- Log::info(sprintf("The index could not be found: %s", $i));
- continue;
- }
-
- try {
- $result = $elasticsearchAlias->createIndex(
- $i,
- [
- 'body' => $indices[$i]
- ],
- $version
- );
-
- Log::info('The indices could be created.', $result);
- } catch (IndexFoundException $e) {
- Log::error($e->getMessage());
- } catch (\Exception $e) {
- Log::error(sprintf(
- "The indices could not be created: %s",
- $e->getMessage()
- ), $index);
- }
- }
- }
-}
diff --git a/src/Console/Commands/Index/Delete.php b/src/Console/Commands/Index/Delete.php
deleted file mode 100644
index 33c8f84..0000000
--- a/src/Console/Commands/Index/Delete.php
+++ /dev/null
@@ -1,60 +0,0 @@
-argument('version');
-
- $indices = $this->getIndices();
-
- if ($this->argument('index') == '_all') {
- $index = array_keys($indices);
- } else {
- $index = explode(',', $this->argument('index'));
- }
-
- try {
- $result = $elasticsearchAlias->deleteIndex($index, $version);
-
- Log::info('The indices could be deleted.', $result);
- } catch (IndexNotFoundException $e) {
- Log::error("The indices could not be found.", $index);
- } catch (\Exception $e) {
- Log::error(sprintf(
- "The indices could not be deleted: %s",
- $e->getMessage()
- ), $index);
- }
- }
-}
diff --git a/src/Console/Commands/Migration/Deploy.php b/src/Console/Commands/Migration/Deploy.php
deleted file mode 100644
index 027f140..0000000
--- a/src/Console/Commands/Migration/Deploy.php
+++ /dev/null
@@ -1,151 +0,0 @@
-getDeployVersions();
-
- $index = $this->argument('index');
- $migrateData = (bool)$this->argument('migrate_data');
-
- if (array_key_exists($index, $version['indices'])) {
- $from_version = $version['indices'][$index]['from'];
- $to_version = $version['indices'][$index]['to'];
-
- $source = null;
- if (array_has($version['indices'][$index], 'source')) {
- if (is_array($version['indices'][$index]['source'])) {
- $source = $version['indices'][$index]['source'];
- }
- }
-
- if ($this->isToVersionHigherThenOldVersion($from_version, $to_version)) {
- if ($from_version == '0.0.0' || $elasticsearchIndex->existIndex([$index], $from_version)) {
- if (!$elasticsearchIndex->existIndex([$index], $to_version)) {
- $indices = $this->getIndices();
- if (array_key_exists($index, $indices)) {
- $this->createIndex($elasticsearchIndex, $index, $indices[$index], $to_version);
- if ($from_version != '0.0.0') {
- if ($elasticsearchIndex->existIndex([$index], $to_version)) {
- if ($migrateData) {
- try {
- $result = $elasticsearchIndex->reindex(
- $index,
- $from_version,
- $to_version,
- [],
- $source
- );
- Log::info('The indices could be reindex.', $result);
- } catch (\Exception $e) {
- Log::error(sprintf(
- "The indices could not be reindex: %s",
- $e->getMessage()
- ), $index);
-
- $elasticsearchIndex->deleteIndex([$index], $to_version);
- }
- }
- }
- }
- } else {
- Log::error("The index could not be found in the config.", [
- 'index' => $index
- ]);
- }
- } else {
- Log::error("The index already exist in this version.", [
- 'index' => $index,
- 'to_version' => $to_version
- ]);
- }
- } else {
- Log::error("The index (from) could not be found.", [
- 'index' => $index,
- 'from_version' => $from_version,
- 'to_version' => $to_version
- ]);
- }
- }
- } else {
- Log::error("The deploy config for the index could not be found.", [
- 'index' => $index
- ]);
- }
- }
-
- private function isToVersionHigherThenOldVersion(string $from, string $to): bool
- {
- $from_numeric = preg_replace('![^0-9]!', '', $from);
- $to_numeric = preg_replace('![^0-9]!', '', $to);
-
- if ($to_numeric <= $from_numeric) {
- Log::error("The from version must be higher then the to version.", [
- 'from_version' => $from,
- 'to_version' => $to
- ]);
-
- return false;
- }
-
- return true;
- }
-
- private function createIndex(
- ElasticsearchIndexContract $elasticsearchIndex,
- string $index,
- array $config,
- string $version
- ) {
- try {
- $result = $elasticsearchIndex->createIndex(
- $index,
- [
- 'body' => $config
- ],
- $version
- );
-
- Log::info('The indices could be created.', $result);
- } catch (IndexFoundException $e) {
- Log::error($e->getMessage());
- } catch (\Exception $e) {
- Log::error(sprintf(
- "The indices could not be created: %s",
- $e->getMessage()
- ), $index);
- }
- }
-}
diff --git a/src/Console/Commands/Migration/Reindex.php b/src/Console/Commands/Migration/Reindex.php
deleted file mode 100644
index 17d188a..0000000
--- a/src/Console/Commands/Migration/Reindex.php
+++ /dev/null
@@ -1,61 +0,0 @@
-argument('index');
- $from_version = $this->argument('from_version');
- $to_version = $this->argument('to_version');
-
- if (!$elasticsearchIndex->existIndex([$index], $from_version)) {
- Log::error("The index (from) could not be found.", [
- 'index' => $index,
- 'from_version' => $from_version,
- 'to_version' => $to_version
- ]);
- } elseif (!$elasticsearchIndex->existIndex([$index], $to_version)) {
- Log::error("The index (to) could not be found.", [
- 'index' => $index,
- 'from_version' => $from_version,
- 'to_version' => $to_version
- ]);
- } else {
- try {
- $elasticsearchIndex->reindex($index, $from_version, $to_version);
- } catch (\Exception $e) {
- Log::error(sprintf(
- "The indices could not be reindex: %s",
- $e->getMessage()
- ), $index);
- }
- }
- }
-}
diff --git a/src/Console/Commands/Version/Overview.php b/src/Console/Commands/Version/Overview.php
deleted file mode 100644
index 8890837..0000000
--- a/src/Console/Commands/Version/Overview.php
+++ /dev/null
@@ -1,57 +0,0 @@
-getVersionedIndices($this->argument('index'));
-
- $headers = ['Name', 'Version', 'Active'];
-
- $rows = [];
-
- foreach ($indices as $index) {
- if (preg_match('/(?[a-z]+)_(?[0-9]+.[0-9]+.[0-9]+)/', $index, $matches)) {
- $rows[$matches['version']] = [
- $matches['name'],
- $matches['version'],
- $elasticsearchAlias->existAlias(
- [$matches['name']],
- [$matches['name']],
- $matches['version']
- ) ? 'true' : 'false'
- ];
- }
- }
-
- $this->table($headers, $rows);
- }
-}
diff --git a/src/Contract/ElasticsearchAliasContract.php b/src/Contract/ElasticsearchAliasContract.php
deleted file mode 100644
index 97a8ed6..0000000
--- a/src/Contract/ElasticsearchAliasContract.php
+++ /dev/null
@@ -1,41 +0,0 @@
-client) {
+ $this->client = $this->buildElasticsearchClient();
+ }
+
+ return $this->client;
+ }
+
+ private function buildElasticsearchClient() : Client
+ {
+ $config = config('triadev-elasticsearch');
+
+ $clientBuilder = ClientBuilder::create();
+ $clientBuilder->setHosts([
+ [
+ 'host' => array_get($config, 'host'),
+ 'port' => array_get($config, 'port'),
+ 'scheme' => array_get($config, 'scheme'),
+ 'user' => array_get($config, 'user'),
+ 'pass' => array_get($config, 'password')
+ ]
+ ]);
+
+ return $clientBuilder->build();
+ }
+}
diff --git a/src/ElasticsearchAlias.php b/src/ElasticsearchAlias.php
deleted file mode 100644
index 3c0d490..0000000
--- a/src/ElasticsearchAlias.php
+++ /dev/null
@@ -1,74 +0,0 @@
-existAlias([$index], [$alias], $version)) {
- return $this->getElasticsearchClient()->indices()->putAlias([
- 'index' => $this->createIndexWithVersion($index, $version),
- 'name' => $alias
- ]);
- }
-
- throw new AliasFoundException($index, $alias, $version);
- }
-
- /**
- * Delete an alias
- *
- * @param string $index
- * @param string $alias
- * @param string|null $version
- * @return array
- * @throws AliasNotFoundException
- */
- public function deleteAlias(string $index, string $alias, string $version = null) : array
- {
- if ($this->existAlias([$index], [$alias], $version)) {
- return $this->getElasticsearchClient()->indices()->deleteAlias([
- 'index' => $this->createIndexWithVersion($index, $version),
- 'name' => $alias
- ]);
- }
-
- throw new AliasNotFoundException($index, $alias, $version);
- }
-
- /**
- * Exist alias
- *
- * @param array $index
- * @param array $alias
- * @param string|null $version
- * @param array $params
- * @return bool
- */
- public function existAlias(array $index, array $alias, ?string $version = null, array $params = []) : bool
- {
- $params['name'] = implode(',', $alias);
-
- $indices = [];
- foreach ($index as $i) {
- $indices[] = $this->createIndexWithVersion($i, $version);
- }
- $params['index'] = implode(',', $indices);
-
- return $this->getElasticsearchClient()->indices()->existsAlias($params);
- }
-}
diff --git a/src/ElasticsearchDocument.php b/src/ElasticsearchDocument.php
deleted file mode 100644
index 41bb290..0000000
--- a/src/ElasticsearchDocument.php
+++ /dev/null
@@ -1,301 +0,0 @@
-createIndexWithVersion($index, $version);
- $params['type'] = $type;
-
- if ($id) {
- $params['id'] = $id;
- }
-
- $result = $this->getElasticsearchClient()->index($params);
-
- return $result;
- }
-
- /**
- * Update document
- *
- * @param string $index
- * @param string $type
- * @param string|null $version
- * @param array $params
- * @param null|string $id
- * @return array
- */
- public function updateDocument(
- string $index,
- string $type,
- string $version = null,
- array $params = [],
- ?string $id = null
- ) : array {
- $params['index'] = $this->createIndexWithVersion($index, $version);
- $params['type'] = $type;
-
- if ($id) {
- $params['id'] = $id;
- }
-
- $result = $this->getElasticsearchClient()->update($params);
-
- return $result;
- }
-
- /**
- * Create documents with bulk
- *
- * @param string $index
- * @param string $type
- * @param string|null $version
- * @param array $body
- * @param array|null $ids
- * @param array|null $parents
- * @return array
- */
- public function createDocumentsWithBulk(
- string $index,
- string $type,
- string $version = null,
- array $body = [],
- ?array $ids = null,
- ?array $parents = null
- ) : array {
- $params = [];
-
- foreach ($body as $key => $b) {
- $esIndex = [
- '_index' => $this->createIndexWithVersion($index, $version),
- '_type' => $type,
- ];
-
- if (is_array($ids) && count($body) == count($ids)) {
- $esIndex['_id'] = $ids[$key];
- }
-
- if (is_array($parents) && count($body) == count($parents)) {
- $esIndex['parent'] = $parents[$key];
- }
-
- $params['body'][] = [
- 'index' => $esIndex
- ];
-
- $params['body'][] = $b;
- }
-
- $result = $this->getElasticsearchClient()->bulk($params);
-
- return $result;
- }
-
- /**
- * Delete document
- *
- * @param string $index
- * @param string $type
- * @param string $id
- * @param string|null $version
- * @param array $params
- * @return array
- */
- public function deleteDocument(
- string $index,
- string $type,
- string $id,
- string $version = null,
- array $params = []
- ) : array {
- $params['index'] = $this->createIndexWithVersion($index, $version);
- $params['type'] = $type;
- $params['id'] = $id;
-
- $result = $this->getElasticsearchClient()->delete($params);
-
- return $result;
- }
-
- /**
- * Delete documents with bulk
- *
- * @param string $index
- * @param string $type
- * @param array $ids
- * @param string|null $version
- * @param array|null $parents
- * @return array
- */
- public function deleteDocumentsWithBulk(
- string $index,
- string $type,
- array $ids,
- string $version = null,
- ?array $parents = null
- ) : array {
- $params = [];
-
- foreach ($ids as $key => $id) {
- $esIndex = [
- '_index' => $this->createIndexWithVersion($index, $version),
- '_type' => $type,
- '_id' => $id
- ];
-
- if (is_array($parents) && count($ids) == count($parents)) {
- $esIndex['parent'] = $parents[$key];
- }
-
- $params['body'][] = [
- 'delete' => $esIndex
- ];
- }
-
- $result = $this->getElasticsearchClient()->bulk($params);
-
- return $result;
- }
-
- /**
- * Delete documents by query
- *
- * @param string $index
- * @param string $type
- * @param array $body
- * @param string|null $version
- * @param array $params
- * @return array
- */
- public function deleteDocumentsByQuery(
- string $index,
- string $type,
- array $body = [],
- string $version = null,
- array $params = []
- ): array {
- $params['index'] = $this->createIndexWithVersion($index, $version);
- $params['type'] = $type;
- $params['body'] = $body;
-
- $result = $this->getElasticsearchClient()->deleteByQuery($params);
-
- return $result;
- }
-
- /**
- * Get document
- *
- * @param string $index
- * @param string $type
- * @param string $id
- * @param string|null $version
- * @return array
- */
- public function getDocument(
- string $index,
- string $type,
- string $id,
- string $version = null
- ) : array {
- $params['index'] = $this->createIndexWithVersion($index, $version);
- $params['type'] = $type;
- $params['id'] = $id;
-
- $result = $this->getElasticsearchClient()->get($params);
-
- return $result;
- }
-
- /**
- * Mget documents
- *
- * @param string $index
- * @param string $type
- * @param array $params
- * @param string|null $version
- * @return array
- */
- public function mgetDocuments(
- string $index,
- string $type,
- array $params = [],
- string $version = null
- ) : array {
- $params['index'] = $this->createIndexWithVersion($index, $version);
- $params['type'] = $type;
-
- $result = $this->getElasticsearchClient()->mget($params);
-
- return $result;
- }
-
- /**
- * Exist document
- *
- * @param string $index
- * @param string $type
- * @param string $id
- * @param array $params
- * @param string|null $version
- * @return bool
- */
- public function existDocument(
- string $index,
- string $type,
- string $id,
- array $params = [],
- string $version = null
- ) : bool {
- $params['index'] = $this->createIndexWithVersion($index, $version);
- $params['type'] = $type;
- $params['id'] = $id;
-
- $result = (bool)$this->getElasticsearchClient()->exists($params);
-
- return $result;
- }
-
- /**
- * Count document
- *
- * @param string $index
- * @param string $type
- * @param array $params
- * @param string|null $version
- * @return int
- */
- public function countDocuments(
- string $index,
- string $type,
- array $params = [],
- string $version = null
- ): int {
- $params['index'] = $this->createIndexWithVersion($index, $version);
- $params['type'] = $type;
-
- $result = $this->getElasticsearchClient()->count($params);
-
- return $result['count'];
- }
-}
diff --git a/src/ElasticsearchIndex.php b/src/ElasticsearchIndex.php
deleted file mode 100644
index 6187e2d..0000000
--- a/src/ElasticsearchIndex.php
+++ /dev/null
@@ -1,135 +0,0 @@
-existIndex([$index], $version)) {
- $params['index'] = $this->createIndexWithVersion($index, $version);
-
- return $this->getElasticsearchClient()->indices()->create($params);
- }
-
- throw new IndexFoundException($index, $version);
- }
-
- /**
- * Delete index
- *
- * @param array $index
- * @param string|null $version
- * @return array
- * @throws IndexNotFoundException
- */
- public function deleteIndex(array $index, string $version = null) : array
- {
- $indices = [];
-
- foreach ($index as $i) {
- if ($this->existIndex([$i], $version)) {
- $indices[] = $this->createIndexWithVersion($i, $version);
- }
- }
-
- if (!empty($indices)) {
- return $this->getElasticsearchClient()->indices()->delete([
- 'index' => implode(',', $indices)
- ]);
- }
-
- throw new IndexNotFoundException(implode(',', $index), $version);
- }
-
- /**
- * Delete all indexes
- *
- * @return array
- */
- public function deleteAllIndexes() : array
- {
- return $this->getElasticsearchClient()->indices()->delete([
- 'index' => '_all'
- ]);
- }
-
- /**
- * Exist index
- *
- * @param array $index
- * @param string|null $version
- * @return bool
- */
- public function existIndex(array $index, ?string $version = null) : bool
- {
- $indices = [];
-
- foreach ($index as $i) {
- $indices[] = $this->createIndexWithVersion($i, $version);
- }
-
- return $this->getElasticsearchClient()->indices()->exists([
- 'index' => implode(',', $indices)
- ]);
- }
-
- /**
- * Get versioned indices
- *
- * @param string $index
- * @return array
- */
- public function getVersionedIndices(string $index) : array
- {
- return array_keys($this->getElasticsearchClient()->indices()->get([
- 'index' => sprintf("%s_*", $index)
- ]));
- }
-
- /**
- * Reindex
- *
- * @param string $index
- * @param string $from_version
- * @param string $to_version
- * @param array $params
- * @param array|null $source
- * @return array
- */
- public function reindex(
- string $index,
- string $from_version,
- string $to_version,
- array $params = [],
- ?array $source = null
- ) : array {
- $params['body'] = [
- 'source' => [
- 'index' => $this->createIndexWithVersion($index, $from_version)
- ],
- 'dest' => [
- 'index' => $this->createIndexWithVersion($index, $to_version)
- ]
- ];
-
- if (is_array($source)) {
- $params['body']['source']['_source'] = $source;
- }
-
- return $this->getElasticsearchClient()->reindex($params);
- }
-}
diff --git a/src/ElasticsearchMapping.php b/src/ElasticsearchMapping.php
deleted file mode 100644
index c87c88b..0000000
--- a/src/ElasticsearchMapping.php
+++ /dev/null
@@ -1,67 +0,0 @@
-elasticsearchIndex = $elasticsearchIndex;
- }
-
- /**
- * Update mapping
- *
- * @param string $index
- * @param string $type
- * @param array $params
- * @param null|string $version
- * @return array
- * @throws IndexNotFoundException
- */
- public function updateMapping(string $index, string $type, array $params, ?string $version = null) : array
- {
- if ($this->elasticsearchIndex->existIndex([$index], $version)) {
- $params['index'] = $this->createIndexWithVersion($index, $version);
- $params['type'] = $type;
-
- return $this->getElasticsearchClient()->indices()->putMapping($params);
- }
-
- throw new IndexNotFoundException($index, $version);
- }
-
- /**
- * Delete mapping
- *
- * @param string $index
- * @param string $type
- * @param null|string $version
- * @return array
- * @throws IndexNotFoundException
- */
- public function deleteMapping(string $index, string $type, ?string $version = null) : array
- {
- if ($this->elasticsearchIndex->existIndex([$index], $version)) {
- return $this->getElasticsearchClient()->indices()->deleteMapping([
- 'index' => $this->createIndexWithVersion($index, $version),
- 'type' => $type
- ]);
- }
-
- throw new IndexNotFoundException($index, $version);
- }
-}
diff --git a/src/ElasticsearchSearch.php b/src/ElasticsearchSearch.php
deleted file mode 100644
index a65729f..0000000
--- a/src/ElasticsearchSearch.php
+++ /dev/null
@@ -1,169 +0,0 @@
-createIndexWithVersion($i, $version);
- }
-
- $params['index'] = implode(',', $indices);
- $params['type'] = implode(',', $type);
- $params['body'] = $body;
-
- $result = $this->getElasticsearchClient()->search($params);
-
- if (!$raw) {
- $searchResult = new SearchResult();
- $searchResult->setTook($result['took']);
- $searchResult->setTimedOut($result['timed_out']);
- $searchResult->setTotal($result['hits']['total']);
- $searchResult->setMaxScore($result['hits']['max_score']);
-
- if (array_key_exists('_scroll_id', $result)) {
- $searchResult->setScrollId($result['_scroll_id']);
- }
-
- $shards = new Shards();
- $shards->setTotal($result['_shards']['total']);
- $shards->setSuccessful($result['_shards']['successful']);
- $shards->setFailed($result['_shards']['failed']);
- $searchResult->setShards($shards);
-
- if ($result['hits']['total'] > 0) {
- foreach ($result['hits']['hits'] as $hit) {
- $h = new Hit();
- $h->setIndex($hit['_index']);
- $h->setType($hit['_type']);
- $h->setId($hit['_id']);
- $h->setScore($hit['_score']);
- $h->setSource($hit['_source']);
-
- if (array_key_exists('inner_hits', $hit)) {
- $h->setInnerHits($hit['inner_hits']);
- }
-
- if (array_key_exists('_routing', $hit)) {
- $h->setRouting($hit['_routing']);
- }
-
- if (array_key_exists('_parent', $hit)) {
- $h->setParent($hit['_parent']);
- }
-
- $searchResult->addHit($h);
- }
- }
-
- if (array_key_exists('aggregations', $result)) {
- $searchResult->setAggs($result['aggregations']);
- }
-
- return $searchResult;
- }
-
- return $result;
- }
-
- /**
- * Scroll
- *
- * @param string $scrollId
- * @param string $scroll
- * @param array $body
- * @param array $params
- * @param bool $raw
- * @return array|SearchResult
- */
- public function scroll(
- string $scrollId,
- string $scroll,
- array $body = [],
- array $params = [],
- bool $raw = false
- ) {
- $body['scroll_id'] = $scrollId;
- $body['scroll'] = $scroll;
-
- $params['body'] = $body;
-
- $result = $this->getElasticsearchClient()->scroll($params);
-
- if (!$raw) {
- $searchResult = new SearchResult();
- $searchResult->setTook($result['took']);
- $searchResult->setTimedOut($result['timed_out']);
- $searchResult->setTotal($result['hits']['total']);
- $searchResult->setMaxScore($result['hits']['max_score']);
-
- if (array_key_exists('_scroll_id', $result)) {
- $searchResult->setScrollId($result['_scroll_id']);
- }
-
- $shards = new Shards();
- $shards->setTotal($result['_shards']['total']);
- $shards->setSuccessful($result['_shards']['successful']);
- $shards->setFailed($result['_shards']['failed']);
- $searchResult->setShards($shards);
-
- if ($result['hits']['total'] > 0) {
- foreach ($result['hits']['hits'] as $hit) {
- $h = new Hit();
- $h->setIndex($hit['_index']);
- $h->setType($hit['_type']);
- $h->setId($hit['_id']);
- $h->setScore($hit['_score']);
- $h->setSource($hit['_source']);
-
- if (array_key_exists('inner_hits', $hit)) {
- $h->setInnerHits($hit['inner_hits']);
- }
-
- if (array_key_exists('_routing', $hit)) {
- $h->setRouting($hit['_routing']);
- }
-
- if (array_key_exists('_parent', $hit)) {
- $h->setParent($hit['_parent']);
- }
-
- $searchResult->addHit($h);
- }
- }
-
- if (array_key_exists('aggregations', $result)) {
- $searchResult->setAggs($result['aggregations']);
- }
-
- return $searchResult;
- }
-
- return $result;
- }
-}
diff --git a/src/Exception/Alias/AliasFoundException.php b/src/Exception/Alias/AliasFoundException.php
deleted file mode 100644
index 633bb4c..0000000
--- a/src/Exception/Alias/AliasFoundException.php
+++ /dev/null
@@ -1,21 +0,0 @@
-index;
- }
-
- /**
- * @param string $index
- */
- public function setIndex(string $index)
- {
- $this->index = $index;
- }
-
- /**
- * @return string
- */
- public function getType(): string
- {
- return $this->type;
- }
-
- /**
- * @param string $type
- */
- public function setType(string $type)
- {
- $this->type = $type;
- }
-
- /**
- * @return string
- */
- public function getId(): string
- {
- return $this->id;
- }
-
- /**
- * @param string $id
- */
- public function setId(string $id)
- {
- $this->id = $id;
- }
-
- /**
- * @return float|null
- */
- public function getScore(): ?float
- {
- return $this->score;
- }
-
- /**
- * @param float|null $score
- */
- public function setScore(?float $score)
- {
- $this->score = $score;
- }
-
- /**
- * @return array
- */
- public function getSource(): array
- {
- return $this->source;
- }
-
- /**
- * @param array $source
- */
- public function setSource(array $source)
- {
- $this->source = $source;
- }
-
- /**
- * @return array|null
- */
- public function getInnerHits(): ?array
- {
- return $this->inner_hits;
- }
-
- /**
- * @param array|null $inner_hits
- */
- public function setInnerHits(?array $inner_hits): void
- {
- $this->inner_hits = $inner_hits;
- }
-
- /**
- * @return null|string
- */
- public function getRouting(): ?string
- {
- return $this->routing;
- }
-
- /**
- * @param null|string $routing
- */
- public function setRouting(?string $routing): void
- {
- $this->routing = $routing;
- }
-
- /**
- * @return null|string
- */
- public function getParent(): ?string
- {
- return $this->parent;
- }
-
- /**
- * @param null|string $parent
- */
- public function setParent(?string $parent): void
- {
- $this->parent = $parent;
- }
-}
diff --git a/src/Models/SearchResult.php b/src/Models/SearchResult.php
deleted file mode 100644
index 9912b8c..0000000
--- a/src/Models/SearchResult.php
+++ /dev/null
@@ -1,181 +0,0 @@
-took;
- }
-
- /**
- * @param int $took
- */
- public function setTook(int $took)
- {
- $this->took = $took;
- }
-
- /**
- * @return Shards
- */
- public function getShards(): Shards
- {
- return $this->shards;
- }
-
- /**
- * @param Shards $shards
- */
- public function setShards(Shards $shards)
- {
- $this->shards = $shards;
- }
-
- /**
- * @return int
- */
- public function getTotal(): int
- {
- return $this->total;
- }
-
- /**
- * @param int $total
- */
- public function setTotal(int $total)
- {
- $this->total = $total;
- }
-
- /**
- * @return float|null
- */
- public function getMaxScore(): ?float
- {
- return $this->max_score;
- }
-
- /**
- * @param float|null $max_score
- */
- public function setMaxScore(?float $max_score)
- {
- $this->max_score = $max_score;
- }
-
- /**
- * @return array
- */
- public function getHits(): array
- {
- return $this->hits;
- }
-
- /**
- * @param array $hits
- */
- public function setHits(array $hits)
- {
- $this->hits = $hits;
- }
-
- /**
- * @param Hit $hit
- */
- public function addHit(Hit $hit)
- {
- $this->hits[] = $hit;
- }
-
- /**
- * @return int
- */
- public function getTimedOut(): int
- {
- return $this->timed_out;
- }
-
- /**
- * @param int $timed_out
- */
- public function setTimedOut(int $timed_out)
- {
- $this->timed_out = $timed_out;
- }
-
- /**
- * @return array
- */
- public function getAggs(): array
- {
- return $this->aggs;
- }
-
- /**
- * @param array $aggs
- */
- public function setAggs(array $aggs)
- {
- $this->aggs = $aggs;
- }
-
- /**
- * @return null|string
- */
- public function getScrollId(): ?string
- {
- return $this->scroll_id;
- }
-
- /**
- * @param null|string $scroll_id
- */
- public function setScrollId(?string $scroll_id): void
- {
- $this->scroll_id = $scroll_id;
- }
-}
diff --git a/src/Models/Shards.php b/src/Models/Shards.php
deleted file mode 100644
index cd40a8e..0000000
--- a/src/Models/Shards.php
+++ /dev/null
@@ -1,68 +0,0 @@
-total;
- }
-
- /**
- * @param int $total
- */
- public function setTotal(int $total)
- {
- $this->total = $total;
- }
-
- /**
- * @return int
- */
- public function getSuccessful(): int
- {
- return $this->successful;
- }
-
- /**
- * @param int $successful
- */
- public function setSuccessful(int $successful)
- {
- $this->successful = $successful;
- }
-
- /**
- * @return int
- */
- public function getFailed(): int
- {
- return $this->failed;
- }
-
- /**
- * @param int $failed
- */
- public function setFailed(int $failed)
- {
- $this->failed = $failed;
- }
-}
diff --git a/src/Provider/ElasticsearchServiceProvider.php b/src/Provider/ElasticsearchServiceProvider.php
index 6748274..2177c9e 100644
--- a/src/Provider/ElasticsearchServiceProvider.php
+++ b/src/Provider/ElasticsearchServiceProvider.php
@@ -1,24 +1,9 @@
mergeConfigFrom($source, 'triadev-elasticsearch');
-
- if ($this->app->runningInConsole()) {
- $this->commands([
- CreateIndex::class,
- DeleteIndex::class,
- CreateAlias::class,
- DeleteAlias::class,
- Overview::class,
- Deploy::class,
- Reindex::class,
- ]);
- }
}
/**
@@ -57,24 +30,8 @@ public function boot()
*/
public function register()
{
- $this->app->singleton(ElasticsearchIndexContract::class, function () {
- return app()->make(ElasticsearchIndex::class);
- });
-
- $this->app->singleton(ElasticsearchAliasContract::class, function () {
- return app()->make(ElasticsearchAlias::class);
- });
-
- $this->app->singleton(ElasticsearchDocumentContract::class, function () {
- return app()->make(ElasticsearchDocument::class);
- });
-
- $this->app->singleton(ElasticsearchSearchContract::class, function () {
- return app()->make(ElasticsearchSearch::class);
- });
-
- $this->app->singleton(ElasticsearchMappingContract::class, function () {
- return app()->make(ElasticsearchMapping::class);
+ $this->app->singleton(ElasticsearchContract::class, function () {
+ return app()->make(Elasticsearch::class);
});
}
}
diff --git a/tests/IntegrationTestCase.php b/tests/IntegrationTestCase.php
deleted file mode 100644
index d53e99d..0000000
--- a/tests/IntegrationTestCase.php
+++ /dev/null
@@ -1,66 +0,0 @@
-set('triadev-elasticsearch', [
- 'host' => 'localhost',
- 'port' => 9200,
- 'scheme' => 'http',
- 'user' => '',
- 'pass' => '',
- 'deploy' => [
- 'version' => [
- 'indices' => [
- 'from' => '0.0.0',
- 'to' => '1.0.0'
- ]
- ]
- ],
- 'snapshot' => [
- 'repository' => 'default',
- 'type' => 'gcs',
- 'settings' => []
- ],
- 'config' => [
- 'retries' => 2,
- 'indices' => [
- 'phpunit' => $this->getMapping()
- ]
- ]
- ]);
- }
-
- public function getMapping() : array
- {
- return [
- 'mappings' => [
- 'phpunit' => [
- 'dynamic' => 'strict',
- 'properties' => [
- 'title' => [
- 'type' => 'text'
- ]
- ]
- ]
- ]
- ];
- }
-}
diff --git a/tests/integration/Console/Commands/Alias/CreateTest.php b/tests/integration/Console/Commands/Alias/CreateTest.php
deleted file mode 100644
index 9c7ec67..0000000
--- a/tests/integration/Console/Commands/Alias/CreateTest.php
+++ /dev/null
@@ -1,52 +0,0 @@
-serviceIndex = app(ElasticsearchIndexContract::class);
- $this->serviceAlias = app(ElasticsearchAliasContract::class);
-
- $this->artisan('triadev:es:index:create', [
- 'index' => 'phpunit',
- 'version' => '1.0.0'
- ]);
-
- $this->assertTrue($this->serviceIndex->existIndex([
- 'phpunit'
- ], '1.0.0'));
-
- if ($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0')) {
- $this->serviceAlias->deleteAlias('phpunit', 'alias', '1.0.0');
- }
- }
-
- /**
- * @test
- */
- public function it_creates_an_alias()
- {
- $this->assertFalse($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0'));
-
- $this->artisan('triadev:es:alias:create', [
- 'index' => 'phpunit',
- 'alias' => 'alias',
- 'version' => '1.0.0'
- ])->assertExitCode(0);
-
- $this->assertTrue($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0'));
- }
-}
diff --git a/tests/integration/Console/Commands/Alias/DeleteTest.php b/tests/integration/Console/Commands/Alias/DeleteTest.php
deleted file mode 100644
index e4d2344..0000000
--- a/tests/integration/Console/Commands/Alias/DeleteTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-serviceIndex = app(ElasticsearchIndexContract::class);
- $this->serviceAlias = app(ElasticsearchAliasContract::class);
-
- $this->artisan('triadev:es:index:create', [
- 'index' => 'phpunit',
- 'version' => '1.0.0'
- ]);
-
- $this->assertTrue($this->serviceIndex->existIndex([
- 'phpunit'
- ], '1.0.0'));
-
- if ($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0')) {
- $this->serviceAlias->deleteAlias('phpunit', 'alias', '1.0.0');
- }
- }
-
- /**
- * @test
- */
- public function it_creates_an_alias()
- {
- $this->artisan('triadev:es:alias:create', [
- 'index' => 'phpunit',
- 'alias' => 'alias',
- 'version' => '1.0.0'
- ])->assertExitCode(0);
-
- $this->assertTrue($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0'));
-
- $this->artisan('triadev:es:alias:delete', [
- 'index' => 'phpunit',
- 'alias' => 'alias',
- 'version' => '1.0.0'
- ])->assertExitCode(0);
-
- $this->assertFalse($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0'));
- }
-}
diff --git a/tests/integration/Console/Commands/Index/CreateTest.php b/tests/integration/Console/Commands/Index/CreateTest.php
deleted file mode 100644
index d2fb9cc..0000000
--- a/tests/integration/Console/Commands/Index/CreateTest.php
+++ /dev/null
@@ -1,33 +0,0 @@
-service = app(ElasticsearchIndexContract::class);
- }
-
- /**
- * @test
- */
- public function it_creates_an_index()
- {
- $this->artisan('triadev:es:index:create', [
- 'index' => 'phpunit',
- 'version' => '1.0.0'
- ]);
-
- $this->assertTrue($this->service->existIndex([
- 'phpunit'
- ], '1.0.0'));
- }
-}
diff --git a/tests/integration/Console/Commands/Index/DeleteTest.php b/tests/integration/Console/Commands/Index/DeleteTest.php
deleted file mode 100644
index ff35ce6..0000000
--- a/tests/integration/Console/Commands/Index/DeleteTest.php
+++ /dev/null
@@ -1,42 +0,0 @@
-service = app(ElasticsearchIndexContract::class);
- }
-
- /**
- * @test
- */
- public function it_deletes_an_index()
- {
- $this->artisan('triadev:es:index:create', [
- 'index' => 'phpunit',
- 'version' => '1.0.0'
- ]);
-
- $this->assertTrue($this->service->existIndex([
- 'phpunit'
- ], '1.0.0'));
-
- $this->artisan('triadev:es:index:delete', [
- 'index' => 'phpunit',
- 'version' => '1.0.0'
- ]);
-
- $this->assertFalse($this->service->existIndex([
- 'phpunit'
- ], '1.0.0'));
- }
-}
diff --git a/tests/integration/Console/Commands/Version/OverviewTest.php b/tests/integration/Console/Commands/Version/OverviewTest.php
deleted file mode 100644
index 559d461..0000000
--- a/tests/integration/Console/Commands/Version/OverviewTest.php
+++ /dev/null
@@ -1,35 +0,0 @@
-service = app(ElasticsearchIndexContract::class);
- }
-
- /**
- * @test
- */
- public function it_gets_all_index_versions()
- {
- $this->artisan('triadev:es:index:create', [
- 'index' => 'phpunit',
- 'version' => '1.0.0'
- ]);
-
- $this->assertTrue($this->service->existIndex([
- 'phpunit'
- ], '1.0.0'));
-
- $this->artisan('triadev:es:version:overview', ['index' => 'phpunit'])->assertExitCode(0);
- }
-}
diff --git a/tests/integration/ElasticsearchAliasTest.php b/tests/integration/ElasticsearchAliasTest.php
deleted file mode 100644
index dc30b74..0000000
--- a/tests/integration/ElasticsearchAliasTest.php
+++ /dev/null
@@ -1,47 +0,0 @@
-deleteAllIndexes();
-
- $this->artisan('triadev:es:index:create', [
- 'index' => 'phpunit',
- 'version' => '1.0.0'
- ]);
-
- $this->assertTrue($indexService->existIndex(['phpunit'], '1.0.0'));
-
- $this->service = app(ElasticsearchAliasContract::class);
- }
-
- /**
- * @test
- */
- public function it_manages_an_alias()
- {
- $this->assertFalse($this->service->existAlias(['phpunit'], ['alias'], '1.0.0'));
-
- $this->service->addAlias('phpunit', 'alias', '1.0.0');
-
- $this->assertTrue($this->service->existAlias(['phpunit'], ['alias'], '1.0.0'));
-
- $this->service->deleteAlias('phpunit', 'alias', '1.0.0');
-
- $this->assertFalse($this->service->existAlias(['phpunit'], ['alias'], '1.0.0'));
- }
-}
diff --git a/tests/integration/ElasticsearchDocumentTest.php b/tests/integration/ElasticsearchDocumentTest.php
deleted file mode 100644
index 8a520e9..0000000
--- a/tests/integration/ElasticsearchDocumentTest.php
+++ /dev/null
@@ -1,339 +0,0 @@
-deleteAllIndexes();
-
- $this->artisan('triadev:es:index:create', [
- 'index' => 'phpunit',
- 'version' => '1.0.0'
- ]);
-
- $this->assertTrue($indexService->existIndex(['phpunit'], '1.0.0'));
-
- $this->service = app(ElasticsearchDocumentContract::class);
- }
-
- /**
- * @test
- */
- public function it_creates_a_document()
- {
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test');
-
- sleep(1);
-
- $this->assertEquals(
- 1,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
-
- $this->assertEquals(
- 'Title',
- $this->service->getDocument(
- 'phpunit',
- 'phpunit',
- 'test',
- '1.0.0'
- )['_source']['title']
- );
- }
-
- /**
- * @test
- */
- public function it_updates_a_document()
- {
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test');
-
- sleep(1);
-
- $this->service->updateDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'doc' => [
- 'title' => 'TitleUpdate'
- ]
- ]
- ], 'test');
-
- sleep(1);
-
- $this->assertEquals(
- 1,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
-
- $this->assertEquals(
- 'TitleUpdate',
- $this->service->getDocument(
- 'phpunit',
- 'phpunit',
- 'test',
- '1.0.0'
- )['_source']['title']
- );
- }
-
- /**
- * @test
- */
- public function it_deletes_a_document()
- {
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test');
-
- sleep(1);
-
- $this->assertEquals(
- 1,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
-
- $this->service->deleteDocument('phpunit', 'phpunit', 'test', '1.0.0');
-
- sleep(1);
-
- $this->assertEquals(
- 0,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
- }
-
- /**
- * @test
- */
- public function it_deletes_documents_with_bulk()
- {
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test1');
-
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test2');
-
- sleep(1);
-
- $this->assertEquals(
- 2,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
-
- $this->service->deleteDocumentsWithBulk('phpunit', 'phpunit', ['test1', 'test2'], '1.0.0');
-
- sleep(1);
-
- $this->assertEquals(
- 0,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
- }
-
- /**
- * @test
- */
- public function it_deletes_documents_by_query()
- {
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test1');
-
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test2');
-
- sleep(1);
-
- $this->assertEquals(
- 2,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
-
- $result = $this->service->deleteDocumentsByQuery('phpunit', 'phpunit', [
- 'query' => [
- 'match' => [
- 'title' => 'Title'
- ]
- ]
- ], '1.0.0', [
- 'refresh' => true
- ]);
-
- $this->assertEquals(2, $result['deleted']);
- }
-
- /**
- * @test
- */
- public function it_gets_a_document()
- {
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test');
-
- sleep(1);
-
- $this->assertEquals(
- 'Title',
- $this->service->getDocument(
- 'phpunit',
- 'phpunit',
- 'test',
- '1.0.0'
- )['_source']['title']
- );
- }
-
- /**
- * @test
- */
- public function it_gets_documents_with_mget()
- {
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title1'
- ]
- ], 'test1');
-
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title2'
- ]
- ], 'test2');
-
- sleep(1);
-
- $result = $this->service->mgetDocuments(
- 'phpunit',
- 'phpunit',
- [
- 'body' => [
- 'ids' => [
- 'test1',
- 'test2'
- ]
- ]
- ],
- '1.0.0'
- );
-
- $this->assertCount(2, $result['docs']);
-
- $this->assertEquals(
- 'Title1',
- $result['docs'][0]['_source']['title']
- );
-
- $this->assertEquals(
- 'Title2',
- $result['docs'][1]['_source']['title']
- );
- }
-
- /**
- * @test
- */
- public function it_checks_if_a_document_exist()
- {
- $this->assertFalse(
- $this->service->existDocument(
- 'phpunit',
- 'phpunit',
- 'test',
- [],
- '1.0.0'
- )
- );
-
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test');
-
- sleep(1);
-
- $this->assertTrue(
- $this->service->existDocument(
- 'phpunit',
- 'phpunit',
- 'test',
- [],
- '1.0.0'
- )
- );
- }
-
- /**
- * @test
- */
- public function it_counts_documents()
- {
- $this->assertEquals(
- 0,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
-
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test1');
-
- sleep(1);
-
- $this->assertEquals(
- 1,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
-
- $this->service->createDocument('phpunit', 'phpunit', '1.0.0', [
- 'body' => [
- 'title' => 'Title'
- ]
- ], 'test2');
-
- sleep(1);
-
- $this->assertEquals(
- 2,
- $this->service->countDocuments('phpunit', 'phpunit', [], '1.0.0')
- );
- }
-}
diff --git a/tests/integration/ElasticsearchIndexTest.php b/tests/integration/ElasticsearchIndexTest.php
deleted file mode 100644
index 7079eb8..0000000
--- a/tests/integration/ElasticsearchIndexTest.php
+++ /dev/null
@@ -1,94 +0,0 @@
-service = app(ElasticsearchIndexContract::class);
-
- $this->service->deleteAllIndexes();
- }
-
- /**
- * @test
- */
- public function it_creates_an_index()
- {
- $this->service->createIndex('phpunit', [
- 'body' => $this->getMapping()
- ]);
-
- $this->assertTrue($this->service->existIndex(['phpunit']));
-
- $this->service->deleteAllIndexes();
- }
-
- /**
- * @test
- * @expectedException \Triadev\Es\Exception\Index\IndexFoundException
- */
- public function it_throws_an_exception_if_index_exist()
- {
- $this->service->createIndex('phpunit', [
- 'body' => $this->getMapping()
- ]);
-
- $this->service->createIndex('phpunit', [
- 'body' => $this->getMapping()
- ]);
-
- $this->service->deleteAllIndexes();
- }
-
- /**
- * @test
- */
- public function it_deletes_all_indices()
- {
- $this->service->createIndex('phpunit1', [
- 'body' => $this->getMapping()
- ]);
-
- $this->service->createIndex('phpunit2', [
- 'body' => $this->getMapping()
- ]);
-
- $this->assertTrue($this->service->existIndex(['phpunit1']));
- $this->assertTrue($this->service->existIndex(['phpunit2']));
-
- $this->service->deleteAllIndexes();
-
- $this->assertFalse($this->service->existIndex(['phpunit1']));
- $this->assertFalse($this->service->existIndex(['phpunit2']));
- }
-
- /**
- * @test
- */
- public function it_returns_versioned_indices()
- {
- $this->service->createIndex('phpunit_1.0.0', [
- 'body' => $this->getMapping()
- ]);
-
- $this->service->createIndex('phpunit_1.0.1', [
- 'body' => $this->getMapping()
- ]);
-
- $indices = $this->service->getVersionedIndices('phpunit');
-
- $this->assertTrue(in_array('phpunit_1.0.0', $indices));
- $this->assertTrue(in_array('phpunit_1.0.1', $indices));
-
- $this->service->deleteAllIndexes();
- }
-}
diff --git a/tests/integration/mapping.php b/tests/integration/mapping.php
deleted file mode 100644
index 1cdd803..0000000
--- a/tests/integration/mapping.php
+++ /dev/null
@@ -1,14 +0,0 @@
- [
- 'phpunit' => [
- 'dynamic' => 'strict',
- 'properties' => [
- 'title' => [
- 'type' => 'text'
- ]
- ]
- ]
- ]
-];
diff --git a/tests/unit/Business/Config/ConfigFacadeTest.php b/tests/unit/Business/Config/ConfigFacadeTest.php
deleted file mode 100644
index d2f2afd..0000000
--- a/tests/unit/Business/Config/ConfigFacadeTest.php
+++ /dev/null
@@ -1,91 +0,0 @@
-assertTrue(is_string($this->getHost()));
- }
-
- /**
- * @test
- * @group LaravelElasticsearch
- */
- public function it_gives_the_elasticsearch_port()
- {
- $this->assertTrue(is_int($this->getPort()));
- }
-
- /**
- * @test
- * @group LaravelElasticsearch
- */
- public function it_gives_the_elasticsearch_scheme()
- {
- $this->assertTrue(is_string($this->getScheme()));
- }
-
- /**
- * @test
- * @group LaravelElasticsearch
- */
- public function it_gives_the_elasticsearch_user()
- {
- $this->assertTrue(is_string($this->getUser()));
- }
-
- /**
- * @test
- * @group LaravelElasticsearch
- */
- public function it_gives_the_elasticsearch_password()
- {
- $this->assertTrue(is_string($this->getPassword()));
- }
-
- /**
- * @test
- * @group LaravelElasticsearch
- */
- public function it_gives_the_retries()
- {
- $this->assertTrue(is_int($this->getRetries()));
- }
-
- /**
- * @test
- * @group LaravelElasticsearch
- */
- public function it_gives_the_indices()
- {
- $this->assertTrue(is_array($this->getIndices()));
- }
-
- /**
- * @test
- * @group LaravelElasticsearch
- */
- public function it_gives_the_deploy_versions()
- {
- $this->assertTrue(is_array($this->getDeployVersions()));
- }
-
- /**
- * @test
- * @group LaravelElasticsearch
- */
- public function it_gives_the_snapshot_config()
- {
- $this->assertTrue(is_array($this->getSnapshot()));
- }
-}
diff --git a/tests/unit/Business/Helper/VersionTest.php b/tests/unit/Business/Helper/VersionTest.php
deleted file mode 100644
index c047c69..0000000
--- a/tests/unit/Business/Helper/VersionTest.php
+++ /dev/null
@@ -1,34 +0,0 @@
-assertEquals(
- 'index',
- $this->createIndexWithVersion('index', null)
- );
- }
-
- /**
- * @test
- * @group LaravelElasticsearch
- */
- public function it_gives_the_index_name_with_version()
- {
- $this->assertEquals(
- 'index_v1',
- $this->createIndexWithVersion('index', 'v1')
- );
- }
-}
diff --git a/tests/unit/ElasticsearchTest.php b/tests/unit/ElasticsearchTest.php
new file mode 100644
index 0000000..ae9bd3a
--- /dev/null
+++ b/tests/unit/ElasticsearchTest.php
@@ -0,0 +1,23 @@
+assertInstanceOf(
+ Client::class,
+ $service->getClient()
+ );
+ }
+}