Skip to content

Commit

Permalink
Remove the concept of type on indexes as it was removed from Elastics…
Browse files Browse the repository at this point in the history
…earch.
  • Loading branch information
slashrsm authored and Janez Urevc committed Mar 6, 2022
1 parent c0ae8c2 commit cba7356
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 306 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 7 additions & 7 deletions docs/document-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```
20 changes: 5 additions & 15 deletions docs/index-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'],
]
]);
}
Expand Down Expand Up @@ -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');
```
5 changes: 2 additions & 3 deletions docs/query-building.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +15,7 @@ class MoviesYouMightLikeQuery extends AbstractQuery
{
public function setup()
{
$this->searchIn('suggestions', 'movies');
$this->searchIn('suggestions');
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/re-useable-fragments.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AuthorsIndex extends AbstractIndex
]
]
],
'mappings' => $this->getTypes()
'mappings' => $this->getMappings()
];
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/Abstracts/AbstractIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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);
}
}
49 changes: 2 additions & 47 deletions src/Abstracts/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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.
*
Expand All @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit cba7356

Please sign in to comment.