From cba7356b6b12c7c7fa6f7f6cd0d19c2c4bafedd9 Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Thu, 23 Sep 2021 11:37:08 +0200 Subject: [PATCH] Remove the concept of type on indexes as it was removed from Elasticsearch. --- README.md | 16 ++--- composer.json | 2 +- docs/document-management.md | 14 ++-- docs/index-management.md | 20 ++---- docs/query-building.md | 5 +- docs/re-useable-fragments.md | 2 +- src/Abstracts/AbstractIndex.php | 18 ++--- src/Abstracts/AbstractQuery.php | 49 +------------- src/Managers/DocumentsManager.php | 37 ++++------ src/Managers/IndicesManager.php | 67 ++----------------- tests/Managers/DocumentsManagerTest.php | 50 +++++++------- tests/Managers/IndicesManagerTest.php | 40 +++++------ tests/Queries/QueryTest.php | 28 +------- tests/dummy/Indexes/AuthorsIndex.php | 32 --------- tests/dummy/Indexes/BooksIndex.php | 10 ++- tests/dummy/Indexes/MoviesIndex.php | 12 ++-- .../Queries/CountMoviesFrom2014Query.php | 2 - 17 files changed, 98 insertions(+), 306 deletions(-) delete mode 100644 tests/dummy/Indexes/AuthorsIndex.php diff --git a/README.md b/README.md index 4a19cd2..21b96bb 100644 --- a/README.md +++ b/README.md @@ -107,23 +107,21 @@ foreach ($result->getResults() as $movie) { ```php $searcher->indicesManager()->exists('listings'); -$searcher->indicesManager()->existsType('suggestions', 'movies'); $searcher->indicesManager()->create('suggestions'); $searcher->indicesManager()->update('suggestions'); $searcher->indicesManager()->delete('suggestions'); -$searcher->indicesManager()->deleteType('suggestions', 'movies'); ``` ### Documents management ```php -$manager->index('suggestions', 'movies', $data); -$manager->bulkIndex('suggestions', 'movies', [$data, $data, $data]); -$manager->update('suggestions', 'movies', 123, ['name' => 'Fight Club 2014']); -$manager->updateOrIndex('suggestions', 'movies', 123, ['name' => 'Fight Club 2014']); -$manager->delete('suggestions', 'movies', 123); -$manager->exists('suggestions', 'movies', 123); -$manager->get('suggestions', 'movies', 123); +$manager->index('suggestions', $data); +$manager->bulkIndex('suggestions', [$data, $data, $data]); +$manager->update('suggestions', 123, ['name' => 'Fight Club 2014']); +$manager->updateOrIndex('suggestions', 123, ['name' => 'Fight Club 2014']); +$manager->delete('suggestions', 123); +$manager->exists('suggestions', 123); +$manager->get('suggestions', 123); ``` ### Cluster Health diff --git a/composer.json b/composer.json index 6778af4..20bb281 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } }, "require": { - "elasticsearch/elasticsearch": "^5.1 | ^6.0 | ^7.0", + "elasticsearch/elasticsearch": "^6.0 | ^7.0", "jdrieghe/array-helpers": "^0.2.0" }, "require-dev": { diff --git a/docs/document-management.md b/docs/document-management.md index 2caf8b1..6cb2e23 100644 --- a/docs/document-management.md +++ b/docs/document-management.md @@ -9,11 +9,11 @@ $data = [ 'id' => 123 'name' => 'Fight club' ]; -$manager->index('suggestions', 'movies', $data); -$manager->bulkIndex('suggestions', 'movies', [$data, $data, $data]); -$manager->update('suggestions', 'movies', 123, ['name' => 'Fight Club 2014']); -$manager->updateOrIndex('suggestions', 'movies', 123, ['name' => 'Fight Club 2014']); -$manager->delete('suggestions', 'movies', 123); -$manager->exists('suggestions', 'movies', 123); -$manager->get('suggestions', 'movies', 123); +$manager->index('suggestions', $data); +$manager->bulkIndex('suggestions', [$data, $data, $data]); +$manager->update('suggestions', 123, ['name' => 'Fight Club 2014']); +$manager->updateOrIndex('suggestions', 123, ['name' => 'Fight Club 2014']); +$manager->delete('suggestions', 123); +$manager->exists('suggestions', 123); +$manager->get('suggestions', 123); ``` diff --git a/docs/index-management.md b/docs/index-management.md index b9cf79b..b1a6be9 100644 --- a/docs/index-management.md +++ b/docs/index-management.md @@ -10,7 +10,7 @@ $manager = $searcher->indicesManager(); ## Defining an index A simple [index](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/_basic_concepts.html#_index) exists -out of a name and one or more types (+mappings). This can be created as: +out of a name and +mappings. This can be created as: ```php class SuggestionsIndex extends \ElasticSearcher\Abstracts\AbstractIndex @@ -22,17 +22,10 @@ class SuggestionsIndex extends \ElasticSearcher\Abstracts\AbstractIndex public function setup() { - $this->setTypes([ - 'books' => [ - 'properties' => [ - 'id' => ['type' => 'integer'], - 'name' => ['type' => 'text'], - ] - ], - 'movies' => [ - 'properties' => [ - 'name' => ['type' => 'text'], - ] + $this->setMappings([ + 'properties' => [ + 'id' => ['type' => 'integer'], + 'name' => ['type' => 'text'], ] ]); } @@ -77,13 +70,10 @@ $searcher->indicesManager()->registeredIndices(); // Indices that exist in the server, not linked to the registered indices. $searcher->indicesManager()->indices(); $searcher->indicesManager()->get('suggestions'); -$searcher->indicesManager()->getType('suggestions', 'books'); // Other $searcher->indicesManager()->exists('listings'); -$searcher->indicesManager()->existsType('suggestions', 'movies'); $searcher->indicesManager()->create('suggestions'); $searcher->indicesManager()->update('suggestions'); $searcher->indicesManager()->delete('suggestions'); -$searcher->indicesManager()->deleteType('suggestions', 'movies'); ``` diff --git a/docs/query-building.md b/docs/query-building.md index 4c86afb..305b208 100644 --- a/docs/query-building.md +++ b/docs/query-building.md @@ -6,8 +6,7 @@ like the ElasticSearch SDK offers. ## Minimum query -This basic example will return all documents in the `movies` type in the `suggestions` index. The type is optional, which -would result in all documents inside the `suggestions` index would be returned. +This basic example will return all documents in the `suggestions` index. ```php use ElasticSearcher\Abstracts\AbstractQuery; @@ -16,7 +15,7 @@ class MoviesYouMightLikeQuery extends AbstractQuery { public function setup() { - $this->searchIn('suggestions', 'movies'); + $this->searchIn('suggestions'); } } ``` diff --git a/docs/re-useable-fragments.md b/docs/re-useable-fragments.md index 7f2e4f5..8a7bbe5 100644 --- a/docs/re-useable-fragments.md +++ b/docs/re-useable-fragments.md @@ -56,7 +56,7 @@ class AuthorsIndex extends AbstractIndex ] ] ], - 'mappings' => $this->getTypes() + 'mappings' => $this->getMappings() ]; } } diff --git a/src/Abstracts/AbstractIndex.php b/src/Abstracts/AbstractIndex.php index ea6af6c..c5e47bd 100644 --- a/src/Abstracts/AbstractIndex.php +++ b/src/Abstracts/AbstractIndex.php @@ -57,19 +57,19 @@ public function getBody() } /** - * @param array $types + * @param array $mappings * * @return array */ - public function setTypes(array $types) + public function setMappings(array $mappings) { - return $this->set('mappings', $types); + return $this->set('mappings', $mappings); } /** * @return array */ - public function getTypes() + public function getMappings() { return $this->get('mappings'); } @@ -91,14 +91,4 @@ public function getSettings() { return $this->get('settings'); } - - /** - * @param string $type - * - * @return array - */ - public function getType($type) - { - return $this->get('mappings.'.$type); - } } diff --git a/src/Abstracts/AbstractQuery.php b/src/Abstracts/AbstractQuery.php index b667202..f49b002 100644 --- a/src/Abstracts/AbstractQuery.php +++ b/src/Abstracts/AbstractQuery.php @@ -27,13 +27,6 @@ abstract class AbstractQuery */ protected $indices = []; - /** - * Types on which the query should be executed. - * - * @var array - */ - protected $types = []; - /** * Data that can be used when building a query. * @@ -100,22 +93,16 @@ public function getData($key = null) } /** - * Define on which indices and types the query should be run. + * Define on which indices the query should be run. * * @param string|array $index - * @param null|string|array $type */ - public function searchIn($index, $type = null) + public function searchIn($index) { // Reset the current state, in case the same instance is re-used. $this->indices = []; - $this->types = []; $this->searchInIndices((array) $index); - - if ($type !== null) { - $this->searchInTypes((array) $type); - } } /** @@ -172,23 +159,6 @@ protected function getQueryStringParam($name) return Arr::get($this->queryStringParams, $name); } - /** - * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-type.html - * @param string $type - */ - protected function setSearchType($type) - { - $this->setQueryStringParam('search_type', $type); - } - - /** - * @return string - */ - protected function getSearchType() - { - return $this->getQueryStringParam('search_type'); - } - /** * Build the query by adding all chunks together. * @@ -203,11 +173,6 @@ protected function buildQuery() // Index always needs to be provided. _all means a cross index search. $query['index'] = empty($this->indices) ? '_all' : implode(',', array_values($this->indices)); - // Type is not required, will search in the entire index. - if (!empty($this->types)) { - $query['type'] = implode(',', array_values($this->types)); - } - // Replace Fragments with their raw body. $query['body'] = $this->fragmentParser->parse($this->body); @@ -237,16 +202,6 @@ public function getIndices() return $this->indices; } - /** - * Types we are searching in. - * - * @return array - */ - public function getTypes() - { - return $this->types; - } - /** * Get the query after being build. * This is what will be sent to the elasticsearch SDK. diff --git a/src/Managers/DocumentsManager.php b/src/Managers/DocumentsManager.php index e09161b..6528430 100644 --- a/src/Managers/DocumentsManager.php +++ b/src/Managers/DocumentsManager.php @@ -16,16 +16,14 @@ class DocumentsManager extends AbstractManager * @return array * * @param string $indexName - * @param string $type * @param array $data */ - public function index($indexName, $type, array $data) + public function index($indexName, array $data) { $index = $this->elasticSearcher->indicesManager()->getRegistered($indexName); $params = [ 'index' => $index->getInternalName(), - 'type' => $type, 'body' => $data ]; @@ -41,17 +39,15 @@ public function index($indexName, $type, array $data) * Index a set of documents. * * @param string $indexName - * @param string $type * @param array $data */ - public function bulkIndex($indexName, $type, array $data) + public function bulkIndex($indexName, array $data) { $params = ['body' => []]; foreach ($data as $item) { $header = [ '_index' => $indexName, - '_type' => $type, ]; if (array_key_exists('id', $item)) { @@ -59,8 +55,8 @@ public function bulkIndex($indexName, $type, array $data) } // The bulk operation expects two JSON objects for each item - // the first one should describe the operation, index, type - // and ID. The later one is the document body. + // the first one should describe the operation, index and ID. + // The later one is the document body. $params['body'][] = ['index' => $header]; $params['body'][] = $item; } @@ -72,16 +68,14 @@ public function bulkIndex($indexName, $type, array $data) * @return array * * @param string $indexName - * @param string $type * @param string $id */ - public function delete($indexName, $type, $id) + public function delete($indexName, $id) { $index = $this->elasticSearcher->indicesManager()->getRegistered($indexName); $params = [ 'index' => $index->getInternalName(), - 'type' => $type, 'id' => $id ]; @@ -94,17 +88,15 @@ public function delete($indexName, $type, $id) * @return array * * @param string $indexName - * @param string $type * @param string $id * @param array $data */ - public function update($indexName, $type, $id, array $data) + public function update($indexName, $id, array $data) { $index = $this->elasticSearcher->indicesManager()->getRegistered($indexName); $params = [ 'index' => $index->getInternalName(), - 'type' => $type, 'id' => $id, 'body' => ['doc' => $data] ]; @@ -116,16 +108,14 @@ public function update($indexName, $type, $id, array $data) * @return bool * * @param string $indexName - * @param string $type * @param string $id */ - public function exists($indexName, $type, $id) + public function exists($indexName, $id) { $index = $this->elasticSearcher->indicesManager()->getRegistered($indexName); $params = [ 'index' => $index->getInternalName(), - 'type' => $type, 'id' => $id, ]; @@ -138,16 +128,15 @@ public function exists($indexName, $type, $id) * @return array * * @param string $indexName - * @param string $type * @param string $id * @param array $data */ - public function updateOrIndex($indexName, $type, $id, array $data) + public function updateOrIndex($indexName, $id, array $data) { - if ($this->exists($indexName, $type, $id)) { - return $this->update($indexName, $type, $id, $data); + if ($this->exists($indexName, $id)) { + return $this->update($indexName, $id, $data); } else { - return $this->index($indexName, $type, $data); + return $this->index($indexName, $data); } } @@ -155,16 +144,14 @@ public function updateOrIndex($indexName, $type, $id, array $data) * @return array * * @param string $indexName - * @param string $type * @param string $id */ - public function get($indexName, $type, $id) + public function get($indexName, $id) { $index = $this->elasticSearcher->indicesManager()->getRegistered($indexName); $params = [ 'index' => $index->getInternalName(), - 'type' => $type, 'id' => $id, ]; diff --git a/src/Managers/IndicesManager.php b/src/Managers/IndicesManager.php index 5f7f195..c2eafd3 100644 --- a/src/Managers/IndicesManager.php +++ b/src/Managers/IndicesManager.php @@ -117,24 +117,6 @@ public function get($indexName) return $this->elasticSearcher->getClient()->indices()->getMapping($params); } - /** - * @return array - * - * @param string $indexName - * @param string $type - */ - public function getType($indexName, $type) - { - $index = $this->getRegistered($indexName); - - $params = [ - 'index' => $index->getInternalName(), - 'type' => $type - ]; - - return $this->elasticSearcher->getClient()->indices()->getMapping($params); - } - /** * @param string $indexName */ @@ -151,7 +133,7 @@ public function create($indexName) } /** - * Update the index and all its types. This should be used when wanting to reflect changes + * Update the index. This should be used when wanting to reflect changes * in the Index object with the elasticsearch server. * * @param string $indexName @@ -160,15 +142,10 @@ public function update($indexName) { $index = $this->getRegistered($indexName); - foreach ($index->getTypes() as $type => $typeBody) { - $params = [ - 'index' => $index->getInternalName(), - 'type' => $type, - 'body' => [$type => $typeBody] - ]; - - $this->elasticSearcher->getClient()->indices()->putMapping($params); - } + $this->elasticSearcher->getClient()->indices()->putMapping([ + 'index' => $index->getInternalName(), + 'body' => ['mappings' => $index->getMappings()] + ]); } /** @@ -185,22 +162,6 @@ public function delete($indexName) $this->elasticSearcher->getClient()->indices()->delete($params); } - /** - * @param string $indexName - * @param string $type - */ - public function deleteType($indexName, $type) - { - $index = $this->getRegistered($indexName); - - $params = [ - 'index' => $index->getInternalName(), - 'type' => $type - ]; - - $this->elasticSearcher->getClient()->indices()->deleteMapping($params); - } - /** * @return bool * @@ -216,22 +177,4 @@ public function exists($indexName) return $this->elasticSearcher->getClient()->indices()->exists($params); } - - /** - * @return bool - * - * @param string $indexName - * @param string $type - */ - public function existsType($indexName, $type) - { - $index = $this->getRegistered($indexName); - - $params = [ - 'index' => $index->getInternalName(), - 'type' => $type - ]; - - return $this->elasticSearcher->getClient()->indices()->existsType($params); - } } diff --git a/tests/Managers/DocumentsManagerTest.php b/tests/Managers/DocumentsManagerTest.php index c7eabd5..86d3daa 100644 --- a/tests/Managers/DocumentsManagerTest.php +++ b/tests/Managers/DocumentsManagerTest.php @@ -33,13 +33,13 @@ public function testIndex() ]; // Make sure the document doesn't exist. - if ($this->documentsManager->exists('movies', 'movies', $id)) { - $this->documentsManager->delete('movies', 'movies', $id); + if ($this->documentsManager->exists('movies', $id)) { + $this->documentsManager->delete('movies', $id); } - $this->documentsManager->index('movies', 'movies', $data); - $this->assertTrue($this->documentsManager->exists('movies', 'movies', $id)); - $this->assertEquals($data, $this->documentsManager->get('movies', 'movies', $id)['_source']); + $this->documentsManager->index('movies', $data); + $this->assertTrue($this->documentsManager->exists('movies', $id)); + $this->assertEquals($data, $this->documentsManager->get('movies', $id)['_source']); } public function testBulkIndex() @@ -62,11 +62,11 @@ public function testBulkIndex() ], ]; - $this->documentsManager->bulkIndex('movies', 'movies', $documents); + $this->documentsManager->bulkIndex('movies', $documents); foreach ($documents as $document) { - $this->assertTrue($this->documentsManager->exists('movies', 'movies', $document['id'])); - $this->assertEquals($document, $this->documentsManager->get('movies', 'movies', $document['id'])['_source']); + $this->assertTrue($this->documentsManager->exists('movies', $document['id'])); + $this->assertEquals($document, $this->documentsManager->get('movies', $document['id'])['_source']); } } @@ -79,10 +79,10 @@ public function testUpdate() 'name' => 'The Guardians of the Galaxy', 'year' => 1915, ]; - $this->documentsManager->updateOrIndex('movies', 'movies', $id, $data); + $this->documentsManager->updateOrIndex('movies', $id, $data); - $this->documentsManager->update('movies', 'movies', $id, ['year' => 2015]); - $this->assertEquals(2015, $this->documentsManager->get('movies', 'movies', $id)['_source']['year']); + $this->documentsManager->update('movies', $id, ['year' => 2015]); + $this->assertEquals(2015, $this->documentsManager->get('movies', $id)['_source']['year']); } public function testDelete() @@ -94,10 +94,10 @@ public function testDelete() 'name' => 'The Guardians of the Galaxy', 'year' => 2015, ]; - $this->documentsManager->updateOrIndex('movies', 'movies', $id, $data); + $this->documentsManager->updateOrIndex('movies', $id, $data); - $this->documentsManager->delete('movies', 'movies', $id); - $this->assertFalse($this->documentsManager->exists('movies', 'movies', $id)); + $this->documentsManager->delete('movies', $id); + $this->assertFalse($this->documentsManager->exists('movies', $id)); } public function testUpdateOrIndex() @@ -105,23 +105,23 @@ public function testUpdateOrIndex() $id = 12345; // Make sure the document doesn't exist. - if ($this->documentsManager->exists('movies', 'movies', $id)) { - $this->documentsManager->delete('movies', 'movies', $id); + if ($this->documentsManager->exists('movies', $id)) { + $this->documentsManager->delete('movies', $id); } - $this->documentsManager->updateOrIndex('movies', 'movies', $id, [ + $this->documentsManager->updateOrIndex('movies', $id, [ 'id' => $id, 'name' => 'Jurasic World', 'year' => 2014, ]); - $this->assertTrue($this->documentsManager->exists('movies', 'movies', $id)); + $this->assertTrue($this->documentsManager->exists('movies', $id)); - $this->documentsManager->updateOrIndex('movies', 'movies', $id, [ + $this->documentsManager->updateOrIndex('movies', $id, [ 'id' => $id, 'name' => 'Jurasic World', 'year' => 2015, ]); - $document = $this->documentsManager->get('movies', 'movies', $id); + $document = $this->documentsManager->get('movies', $id); $this->assertEquals('2015', $document['_source']['year']); } @@ -134,12 +134,12 @@ public function testWithPrefixedIndex() ]; // Make sure the document doesn't exist. - if ($this->documentsManager->exists('books', 'books', $id)) { - $this->documentsManager->delete('books', 'books', $id); + if ($this->documentsManager->exists('books', $id)) { + $this->documentsManager->delete('books', $id); } - $this->documentsManager->index('books', 'books', $data); - $this->assertTrue($this->documentsManager->exists('books', 'books', $id)); - $this->assertEquals($data, $this->documentsManager->get('books', 'books', $id)['_source']); + $this->documentsManager->index('books', $data); + $this->assertTrue($this->documentsManager->exists('books', $id)); + $this->assertEquals($data, $this->documentsManager->get('books', $id)['_source']); } } diff --git a/tests/Managers/IndicesManagerTest.php b/tests/Managers/IndicesManagerTest.php index 154bc83..fd21a53 100644 --- a/tests/Managers/IndicesManagerTest.php +++ b/tests/Managers/IndicesManagerTest.php @@ -1,7 +1,6 @@ indicesManager = $this->getElasticSearcher()->indicesManager(); - $this->indicesManager->register(new AuthorsIndex()); - if ($this->indicesManager->exists('authors')) { - $this->indicesManager->delete('authors'); + $this->indicesManager->register(new MoviesIndex()); + if ($this->indicesManager->exists('movies')) { + $this->indicesManager->delete('movies'); } } @@ -48,37 +47,28 @@ public function testRegister() public function testCreating() { - $this->indicesManager->create('authors'); + $this->indicesManager->create('movies'); - $this->assertTrue($this->indicesManager->exists('authors')); - $this->assertTrue($this->indicesManager->existsType('authors', 'directors')); - $this->assertTrue($this->indicesManager->existsType('authors', 'producers')); + $this->assertTrue($this->indicesManager->exists('movies')); } public function testGetting() { - $this->indicesManager->create('authors'); - $authorsIndex = new AuthorsIndex(); + $this->indicesManager->create('movies'); + $moviesIndex = new MoviesIndex(); - $this->assertArrayHasKey('authors', $this->indicesManager->indices()); + $this->assertArrayHasKey('movies', $this->indicesManager->indices()); - $expectedIndex = ['authors' => ['mappings' => $authorsIndex->getTypes()]]; - $this->assertEquals($expectedIndex, $this->indicesManager->get('authors')); - - $expectedIndex = [ - 'authors' => [ - 'mappings' => array_intersect_key($authorsIndex->getTypes(), array_flip((array) 'producers')), - ], - ]; - $this->assertEquals($expectedIndex, $this->indicesManager->getType('authors', 'producers')); - } + $expectedIndex = ['movies' => ['mappings' => $moviesIndex->getMappings()]]; + $this->assertEquals($expectedIndex, $this->indicesManager->get('movies')); + } public function testDeleting() { - $this->indicesManager->create('authors'); - $this->indicesManager->delete('authors'); + $this->indicesManager->create('movies'); + $this->indicesManager->delete('movies'); - $this->assertFalse($this->indicesManager->exists('authors')); + $this->assertFalse($this->indicesManager->exists('movies')); } public function testWithPrefixedIndex() @@ -92,7 +82,7 @@ public function testWithPrefixedIndex() $this->indicesManager->create('books'); $this->assertTrue($this->indicesManager->exists('books')); - $expectedIndex = ['prefix_books' => ['mappings' => $booksIndex->getTypes()]]; + $expectedIndex = ['prefix_books' => ['mappings' => $booksIndex->getMappings()]]; $this->assertEquals($expectedIndex, $this->indicesManager->get('books')); $this->indicesManager->delete('books'); diff --git a/tests/Queries/QueryTest.php b/tests/Queries/QueryTest.php index 415939f..bf55aea 100644 --- a/tests/Queries/QueryTest.php +++ b/tests/Queries/QueryTest.php @@ -29,7 +29,7 @@ protected function setUp(): void // Index some test data. $documentsManager = $this->getElasticSearcher()->documentsManager(); - $documentsManager->bulkIndex('movies', 'movies', + $documentsManager->bulkIndex('movies', [ ['id' => 1, 'name' => 'Fury', 'year' => 2014], ['id' => 2, 'name' => 'Interstellar', 'year' => 2014], @@ -54,11 +54,9 @@ public function testQueryBuilding() $query->run(); // Needed because this calls setUp inside the query. $this->assertEquals(['movies'], $query->getIndices()); - $this->assertEquals(['movies'], $query->getTypes()); $expectedQuery = [ 'index' => 'movies', - 'type' => 'movies', 'body' => [ 'query' => [ 'bool' => [ @@ -80,7 +78,6 @@ public function testQueryBuildingWithData() $expectedQuery = [ 'index' => 'movies', - 'type' => 'movies', 'body' => [ 'query' => [ 'bool' => [ @@ -102,7 +99,6 @@ public function testQueryBuildingWithNestedFragments() $expectedQuery = [ 'index' => 'movies', - 'type' => 'movies', 'body' => [ 'query' => [ 'bool' => [ @@ -116,31 +112,15 @@ public function testQueryBuildingWithNestedFragments() $this->assertEquals($expectedQuery, $query->getRawQuery()); } - public function testSettingIndicesAndTypes() + public function testSettingIndices() { $query = $this->getMockForAbstractClass('\ElasticSearcher\Abstracts\AbstractQuery', [$this->getElasticSearcher()]); $query->searchIn('movies'); $this->assertEquals(['movies'], $query->getIndices()); - $this->assertEquals([], $query->getTypes()); - $query->searchIn('movies', 'authors'); + $query->searchIn(['movies']); $this->assertEquals(['movies'], $query->getIndices()); - $this->assertEquals(['authors'], $query->getTypes()); - - $query->searchIn(['movies'], ['authors', 'directors']); - $this->assertEquals(['movies'], $query->getIndices()); - $this->assertEquals(['authors', 'directors'], $query->getTypes()); - } - - public function testSettingSearchType() - { - $query = new CountMoviesFrom2014Query($this->getElasticSearcher()); - - $raw = $query->getRawQuery(); - - $this->assertArrayHasKey('search_type', $raw); - $this->assertEquals('count', $raw['search_type']); } public function testQueryBuildingWithPrefixedIndex() @@ -149,11 +129,9 @@ public function testQueryBuildingWithPrefixedIndex() $query->run(); // Needed because this calls setUp inside the query. $this->assertEquals(['prefix_books'], $query->getIndices()); - $this->assertEquals(['books'], $query->getTypes()); $expectedQuery = [ 'index' => 'prefix_books', - 'type' => 'books', 'body' => [ 'query' => [ 'bool' => [ diff --git a/tests/dummy/Indexes/AuthorsIndex.php b/tests/dummy/Indexes/AuthorsIndex.php deleted file mode 100644 index 84ac631..0000000 --- a/tests/dummy/Indexes/AuthorsIndex.php +++ /dev/null @@ -1,32 +0,0 @@ -setTypes([ - 'directors' => [ - 'properties' => [ - 'id' => ['type' => 'integer'], - 'first_name' => ['type' => 'text'], - 'last_name' => ['type' => 'text'] - ] - ], - 'producers' => [ - 'properties' => [ - 'id' => ['type' => 'integer'], - 'name' => ['type' => 'text'] - ] - ] - ]); - } -} diff --git a/tests/dummy/Indexes/BooksIndex.php b/tests/dummy/Indexes/BooksIndex.php index 491dc5f..927edb7 100644 --- a/tests/dummy/Indexes/BooksIndex.php +++ b/tests/dummy/Indexes/BooksIndex.php @@ -18,12 +18,10 @@ public function getInternalName() public function setup() { - $this->setTypes([ - 'books' => [ - 'properties' => [ - 'id' => ['type' => 'integer'], - 'name' => ['type' => 'text'], - ] + $this->setMappings([ + 'properties' => [ + 'id' => ['type' => 'integer'], + 'name' => ['type' => 'text'], ] ]); } diff --git a/tests/dummy/Indexes/MoviesIndex.php b/tests/dummy/Indexes/MoviesIndex.php index f5a1de9..3e9f1aa 100644 --- a/tests/dummy/Indexes/MoviesIndex.php +++ b/tests/dummy/Indexes/MoviesIndex.php @@ -13,13 +13,11 @@ public function getName() public function setup() { - $this->setTypes([ - 'movies' => [ - 'properties' => [ - 'id' => ['type' => 'integer'], - 'name' => ['type' => 'text'], - 'year' => ['type' => 'integer'], - ] + $this->setMappings([ + 'properties' => [ + 'id' => ['type' => 'integer'], + 'name' => ['type' => 'text'], + 'year' => ['type' => 'integer'], ] ]); } diff --git a/tests/dummy/Queries/CountMoviesFrom2014Query.php b/tests/dummy/Queries/CountMoviesFrom2014Query.php index 4c6f265..71b1ffb 100644 --- a/tests/dummy/Queries/CountMoviesFrom2014Query.php +++ b/tests/dummy/Queries/CountMoviesFrom2014Query.php @@ -12,7 +12,5 @@ public function setup() $this->searchIn('movies', 'movies'); $this->set('query.bool.filter', [new TermQuery('year', 2014)]); - - $this->setSearchType('count'); } }