Skip to content

Commit

Permalink
supporting parameter include_type_name as explain on elasticsearch bl…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nexucis committed Jun 23, 2019
1 parent 7ada457 commit af8fa29
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 52 deletions.
28 changes: 15 additions & 13 deletions src/Nexucis/Elasticsearch/Helper/Nodowntime/IndexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ public function deleteIndexByAlias($alias)
* it is strongly advised to not set this parameter to false with ElasticSearch 2.4. In fact, it would be preferable to create an asynchronous process that executes this task.
* If you set it to false, don't forget to put an alias to the new index when the corresponding task is gone.
* @return string : the task ID if the parameter $waitForCompletion is set to false, acknowledge if not
* @throws RuntimeException
* @throws IndexNotFoundException
* @throws IndexAlreadyExistException
* @throws IndexNotFoundException
*/
public function copyIndex($aliasSrc, $aliasDest, $refresh = false, $waitForCompletion = true)
{
Expand Down Expand Up @@ -158,7 +157,6 @@ public function copyIndex($aliasSrc, $aliasDest, $refresh = false, $waitForCompl
* it is strongly advised to not set this parameter to false with ElasticSearch 2.4.
* If you set it to false, don't forget to remove the old index and to switch the alias after the task is gone.
* @return string : the task ID if the parameter $waitForCompletion is set to false, acknowledge if not
* @throws RuntimeException
* @throws IndexNotFoundException
*/
public function reindex($alias, $refresh = false, $needToCreateIndexDest = true, $waitForCompletion = true)
Expand Down Expand Up @@ -251,7 +249,6 @@ public function addSettings($alias, $settings)
* it is strongly advised to not set this parameter to false with ElasticSearch 2.4.
* If you set it to false, don't forget to remove the old index and to switch the alias after the task is gone.
* @return string : the task ID if the parameter $waitForCompletion is set to false, acknowledge if not
* @throws RuntimeException
* @throws IndexNotFoundException
*/
public function updateSettings($alias, $settings, $refresh = false, $needReindexation = true, $waitForCompletion = true)
Expand Down Expand Up @@ -310,11 +307,13 @@ public function updateSettings($alias, $settings, $refresh = false, $needReindex
* @param bool $waitForCompletion : According to the official documentation (https://www.elastic.co/guide/en/elasticsearch/reference/2.4/docs-reindex.html),
* it is strongly advised to not set this parameter to false with ElasticSearch 2.4.
* If you set it to false, don't forget to remove the old index and to switch the alias after the task is gone.
* @param bool $includeTypeName : Indicate if you still use a type in your index. To be ready for the next release (v8), you should consider to set this parameter to false.
* Which means you have to change your mapping to remove the usage of the type. See more here: https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0
* This parameter will be removed in the next release
* @return string : the task ID if the parameter $waitForCompletion is set to false, acknowledge if not
* @throws RuntimeException
* @throws IndexNotFoundException
*/
public function updateMappings($alias, $mapping, $refresh = false, $needReindexation = true, $waitForCompletion = true)
public function updateMappings($alias, $mapping, $refresh = false, $needReindexation = true, $waitForCompletion = true, $includeTypeName = true)
{
if (!$this->existsAlias($alias)) {
throw new IndexNotFoundException($alias);
Expand All @@ -340,6 +339,10 @@ public function updateMappings($alias, $mapping, $refresh = false, $needReindexa

$this->copySettings($params, $settings);

if ($includeTypeName) {
$params['include_type_name'] = true;
}

$result = $this->client->indices()->create($params);

if ($result['acknowledged'] && $needReindexation) {
Expand Down Expand Up @@ -402,7 +405,7 @@ public function getSettings($alias)

/**
* @param $alias string [REQUIRED] the name of the index or the name of the alias
* @param @deprecated $type string [REQUIRED] the type of the document
* @param $type string [REQUIRED] the type of the document
* @param $id string|int [REQUIRED] the document ID
* @param $refresh bool
* @return callable|array
Expand Down Expand Up @@ -439,7 +442,7 @@ public function getAllDocuments($alias, $from = 0, $size = 10)
/**
* @param string $alias [REQUIRED]
* @param array|null $query
* @param @deprecated string $type. This parameter will be removed in the next major release
* @param string $type . This parameter will be removed in the next major release
* @param int $from the offset from the first result you want to fetch (0 by default)
* @param int $size allows you to configure the maximum amount of hits to be returned. (10 by default)
* @return callable|array
Expand Down Expand Up @@ -467,7 +470,7 @@ public function searchDocuments($alias, $query = null, $type = null, $from = 0,

/**
* @param $alias [REQUIRED]
* @param @deprecated string $type. This parameter will be removed in the next major release
* @param string $type . This parameter will be removed in the next major release
* @param array|null $body
* @param SearchParameter $searchParameter
* @return callable|array
Expand Down Expand Up @@ -501,7 +504,7 @@ public function advancedSearchDocument($alias, $type = null, $body = null, $sear
/**
* @param string $index [REQUIRED] If the alias is associated to an unique index, you can pass an alias rather than an index
* @param $id [REQUIRED]
* @param @deprecated string $type [REQUIRED]
* @param string $type [REQUIRED]
* @param array $body [REQUIRED] : actual document to update
* @param bool $refresh wait until the result are visible to search
* @return boolean : true if the document has been updated. Otherwise, the document has been created.
Expand All @@ -518,7 +521,7 @@ public function updateDocument($index, $id, $type, $body, $refresh = false)
/**
* @param string $index [REQUIRED] If the alias is associated to an unique index, you can pass an alias rather than an index
* @param $id [REQUIRED]
* @param @deprecated string $type [REQUIRED]
* @param string $type [REQUIRED]
* @param array $body [REQUIRED] : actual document to create
* @param bool $refresh wait until the result are visible to search
* @return boolean : true if the document has been created.
Expand Down Expand Up @@ -562,7 +565,7 @@ public function deleteAllDocuments($alias)
/**
* @param $alias [REQUIRED]
* @param $id [REQUIRED]
* @param @deprecated string $type [REQUIRED]
* @param string $type [REQUIRED]
* @param boolean $refresh , Refresh the index after performing the operation
* @return void
* @throws IndexNotFoundException
Expand Down Expand Up @@ -734,7 +737,6 @@ protected function copyMappingAndSetting($indexSource, $indexDest)

$this->copySettings($params, $settingSource);


$this->client->indices()->create($params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Elasticsearch\Client;
use Elasticsearch\Common\Exceptions\InvalidArgumentException;
use Elasticsearch\Common\Exceptions\RuntimeException;
use Nexucis\Elasticsearch\Helper\Nodowntime\Exceptions\IndexAlreadyExistException;
use Nexucis\Elasticsearch\Helper\Nodowntime\Exceptions\IndexNotFoundException;
use Nexucis\Elasticsearch\Helper\Nodowntime\Parameter\SearchParameter;
Expand Down Expand Up @@ -50,9 +49,8 @@ public function deleteIndexByAlias($alias);
* it is strongly advised to not set this parameter to false with ElasticSearch 2.4. In fact, it would be preferable to create an asynchronous process that executes this task.
* If you set it to false, don't forget to put an alias to the new index when the corresponding task is gone.
* @return string : the task ID if the parameter $waitForCompletion is set to false, acknowledge if not
* @throws RuntimeException
* @throws IndexNotFoundException
* @throws IndexAlreadyExistException
* @throws IndexNotFoundException
*/
public function copyIndex($aliasSrc, $aliasDest, $refresh = false, $waitForCompletion = true);

Expand All @@ -64,7 +62,6 @@ public function copyIndex($aliasSrc, $aliasDest, $refresh = false, $waitForCompl
* it is strongly advised to not set this parameter to false with ElasticSearch 2.4.
* If you set it to false, don't forget to remove the old index and to switch the alias after the task is gone.
* @return string : the task ID if the parameter $waitForCompletion is set to false, acknowledge if not
* @throws RuntimeException
* @throws IndexNotFoundException
*/
public function reindex($alias, $refresh = false, $needToCreateIndexDest = true, $waitForCompletion = true);
Expand Down Expand Up @@ -95,7 +92,6 @@ public function addSettings($alias, $settings);
* it is strongly advised to not set this parameter to false with ElasticSearch 2.4.
* If you set it to false, don't forget to remove the old index and to switch the alias after the task is gone.
* @return string : the task ID if the parameter $waitForCompletion is set to false, acknowledge if not
* @throws RuntimeException
* @throws IndexNotFoundException
*/
public function updateSettings($alias, $settings, $refresh = false, $needReindexation = true, $waitForCompletion = true);
Expand All @@ -112,11 +108,13 @@ public function updateSettings($alias, $settings, $refresh = false, $needReindex
* @param bool $waitForCompletion : According to the official documentation (https://www.elastic.co/guide/en/elasticsearch/reference/2.4/docs-reindex.html),
* it is strongly advised to not set this parameter to false with ElasticSearch 2.4.
* If you set it to false, don't forget to remove the old index and to switch the alias after the task is gone.
* @param bool $includeTypeName : Indicate if you still use a type in your index. To be ready for the next release (v8), you should consider to set this parameter to false.
* Which means you have to change your mapping to remove the usage of the type. See more here: https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0
* This parameter will be removed in the next release
* @return string : the task ID if the parameter $waitForCompletion is set to false, acknowledge if not
* @throws RuntimeException
* @throws IndexNotFoundException
*/
public function updateMappings($alias, $mapping, $refresh = false, $needReindexation = true, $waitForCompletion = true);
public function updateMappings($alias, $mapping, $refresh = false, $needReindexation = true, $waitForCompletion = true, $includeTypeName = true);

/**
* @return array
Expand Down Expand Up @@ -149,25 +147,25 @@ public function getDocument($alias, $type, $id, $refresh = false);
* @param string $alias [REQUIRED]
* @param int $from the offset from the first result you want to fetch (0 by default)
* @param int $size allows you to configure the maximum amount of hits to be returned. (10 by default)
* @throws IndexNotFoundException
* @return callable|array
* @throws IndexNotFoundException
*/
public function getAllDocuments($alias, $from = 0, $size = 10);

/**
* @param string $alias [REQUIRED]
* @param array|null $query
* @param @deprecated string $type
* @param string $type
* @param int $from the offset from the first result you want to fetch (0 by default)
* @param int $size allows you to configure the maximum amount of hits to be returned. (10 by default)
* @throws IndexNotFoundException
* @return callable|array
* @throws IndexNotFoundException
*/
public function searchDocuments($alias, $query = null, $type = null, $from = 0, $size = 10);

/**
* @param $alias
* @param @deprecated string $type
* @param string $type
* @param array|null $body
* @param SearchParameter $searchParameter
* @return callable|array
Expand All @@ -178,7 +176,7 @@ public function advancedSearchDocument($alias, $type = null, $body = null, $sear
/**
* @param string $index [REQUIRED] If the alias is associated to an unique index, you can pass an alias rather than an index
* @param $id [REQUIRED]
* @param @deprecated string $type [REQUIRED]
* @param string $type [REQUIRED]
* @param array $body [REQUIRED] : actual document to update
* @param bool $refresh wait until the result are visible to search
* @return boolean : true if the document has been updated. Otherwise, the document has been created.
Expand All @@ -189,7 +187,7 @@ public function updateDocument($index, $id, $type, $body, $refresh = false);
/**
* @param string $index [REQUIRED] If the alias is associated to an unique index, you can pass an alias rather than an index
* @param $id [REQUIRED]
* @param @deprecated string $type [REQUIRED]
* @param string $type [REQUIRED]
* @param array $body [REQUIRED] : actual document to create
* @param bool $refresh wait until the result are visible to search
* @return boolean : true if the document has been created.
Expand All @@ -202,14 +200,13 @@ public function addDocument($index, $type, $body, $id = null, $refresh = false);
*
* @param string $alias [REQUIRED]
* @return void
* @throws IndexNotFoundException
*/
public function deleteAllDocuments($alias);

/**
* @param $alias [REQUIRED]
* @param $id [REQUIRED]
* @param @deprecated string $type [REQUIRED]
* @param string $type [REQUIRED]
* @param boolean $refresh , Refresh the index after performing the operation
* @return void
* @throws IndexNotFoundException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ public function aliasDataProvider()
];
}

public function aliasDataProviderWithTypeName()
{
return [
'latin-char-with-type' => [
'myindextest',
true
],
'latin-char-without-type' => [
'myindextest',
false
],
'utf-8-char-with-type' => [
'⿇⽸⾽',
true
],
'utf-8-char-without-type' => [
'⿇⽸⾽',
false
],
];
}

protected function createIndex2($alias)
{
$index = $alias . IndexHelper::INDEX_NAME_CONVENTION_2;
Expand Down
Loading

0 comments on commit af8fa29

Please sign in to comment.