| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807 |
- <?php
- /**
- * @link http://www.yiiframework.com/
- * @copyright Copyright (c) 2008 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- */
- namespace yii\elasticsearch;
- use yii\base\Component;
- use yii\base\InvalidCallException;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Json;
- /**
- * The Command class implements the API for accessing the Elasticsearch REST API.
- *
- * Check the [Elasticsearch guide](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)
- * for details on these commands.
- *
- * @author Carsten Brandt <mail@cebe.cc>
- * @since 2.0
- */
- class Command extends Component
- {
- /**
- * @var Connection
- */
- public $db;
- /**
- * @var string|array the indexes to execute the query on. Defaults to null meaning all indexes
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-multi-index-type
- */
- public $index;
- /**
- * @var string|array|null the types to execute the query on. Defaults to null meaning all types
- */
- public $type;
- /**
- * @var array list of arrays or json strings that become parts of a query
- */
- public $queryParts;
- /**
- * @var array options to be appended to the query URL, such as "search_type" for search or "timeout" for delete
- */
- public $options = [];
- /**
- * Sends a request to the _search API and returns the result
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- */
- public function search($options = [])
- {
- $query = $this->queryParts;
- if (empty($query)) {
- $query = '{}';
- }
- if (is_array($query)) {
- $query = Json::encode($query);
- }
- $url = [$this->index !== null ? $this->index : '_all'];
- if ($this->db->dslVersion < 7 && $this->type !== null) {
- $url[] = $this->type;
- }
- $url[] = '_search';
- return $this->db->get($url, array_merge($this->options, $options), $query);
- }
- /**
- * Sends a request to the delete by query
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- */
- public function deleteByQuery($options = [])
- {
- if (!isset($this->queryParts['query'])) {
- throw new InvalidCallException('Can not call deleteByQuery when no query is given.');
- }
- $query = [
- 'query' => $this->queryParts['query'],
- ];
- if (isset($this->queryParts['filter'])) {
- $query['filter'] = $this->queryParts['filter'];
- }
- $query = Json::encode($query);
- $url = [$this->index !== null ? $this->index : '_all'];
- if ($this->type !== null) {
- $url[] = $this->type;
- }
- $url[] = '_delete_by_query';
- return $this->db->post($url, array_merge($this->options, $options), $query);
- }
- /**
- * Sends a suggest request to the _search API and returns the result
- * @param string|array $suggester the suggester body
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html
- */
- public function suggest($suggester, $options = [])
- {
- if (empty($suggester)) {
- $suggester = '{}';
- }
- if (is_array($suggester)) {
- $suggester = Json::encode($suggester);
- }
- $body = '{"suggest":'.$suggester.',"size":0}';
- $url = [
- $this->index !== null ? $this->index : '_all',
- '_search'
- ];
- $result = $this->db->post($url, array_merge($this->options, $options), $body);
- return $result['suggest'];
- }
- /**
- * Inserts a document into an index
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @param string|array $data json string or array of data to store
- * @param string|null $id the documents id. If not specified Id will be automatically chosen
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html
- */
- public function insert($index, $type, $data, $id = null, $options = [])
- {
- if (empty($data)) {
- $body = '{}';
- } else {
- $body = is_array($data) ? Json::encode($data) : $data;
- }
- if ($id !== null) {
- if ($this->db->dslVersion >= 7) {
- return $this->db->put([$index, '_doc', $id], $options, $body);
- } else {
- return $this->db->put([$index, $type, $id], $options, $body);
- }
- } else {
- if ($this->db->dslVersion >= 7) {
- return $this->db->post([$index, '_doc'], $options, $body);
- } else {
- return $this->db->post([$index, $type], $options, $body);
- }
- }
- }
- /**
- * gets a document from the index
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @param string $id the documents id.
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html
- */
- public function get($index, $type, $id, $options = [])
- {
- if ($this->db->dslVersion >= 7) {
- return $this->db->get([$index, '_doc', $id], $options);
- } else {
- return $this->db->get([$index, $type, $id], $options);
- }
- }
- /**
- * gets multiple documents from the index
- *
- * TODO allow specifying type and index + fields
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @param string[] $ids the documents ids as values in array.
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html
- */
- public function mget($index, $type, $ids, $options = [])
- {
- $body = Json::encode(['ids' => array_values($ids)]);
- if ($this->db->dslVersion >= 7) {
- return $this->db->get([$index, '_doc', '_mget'], $options, $body);
- } else {
- return $this->db->get([$index, $type, '_mget'], $options, $body);
- }
- }
- /**
- * gets a documents _source from the index (>=v0.90.1)
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @param string $id the documents id.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source
- */
- public function getSource($index, $type, $id)
- {
- if ($this->db->dslVersion >= 7) {
- return $this->db->get([$index, '_doc', $id]);
- } else {
- return $this->db->get([$index, $type, $id]);
- }
- }
- /**
- * gets a document from the index
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @param string $id the documents id.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html
- */
- public function exists($index, $type, $id)
- {
- if ($this->db->dslVersion >= 7) {
- return $this->db->head([$index, '_doc', $id]);
- } else {
- return $this->db->head([$index, $type, $id]);
- }
- }
- /**
- * deletes a document from the index
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @param string $id the documents id.
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
- */
- public function delete($index, $type, $id, $options = [])
- {
- if ($this->db->dslVersion >= 7) {
- return $this->db->delete([$index, '_doc', $id], $options);
- } else {
- return $this->db->delete([$index, $type, $id], $options);
- }
- }
- /**
- * updates a document
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @param string $id the documents id.
- * @param mixed $data
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
- */
- public function update($index, $type, $id, $data, $options = [])
- {
- $body = [
- 'doc' => empty($data) ? new \stdClass() : $data,
- ];
- if (isset($options["detect_noop"])) {
- $body["detect_noop"] = $options["detect_noop"];
- unset($options["detect_noop"]);
- }
- if ($this->db->dslVersion >= 7) {
- return $this->db->post([$index, '_doc', $id, '_update'], $options, Json::encode($body));
- } else {
- return $this->db->post([$index, $type, $id, '_update'], $options, Json::encode($body));
- }
- }
- // TODO bulk https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
- /**
- * creates an index
- * @param string $index Index that the document belongs to.
- * @param null|array $configuration
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
- */
- public function createIndex($index, $configuration = null)
- {
- $body = $configuration !== null ? Json::encode($configuration) : null;
- return $this->db->put([$index], [], $body);
- }
- /**
- * deletes an index
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html
- */
- public function deleteIndex($index)
- {
- return $this->db->delete([$index]);
- }
- /**
- * deletes all indexes
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html
- */
- public function deleteAllIndexes()
- {
- return $this->db->delete(['_all']);
- }
- /**
- * checks whether an index exists
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html
- */
- public function indexExists($index)
- {
- return $this->db->head([$index]);
- }
- /**
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-types-exists.html
- */
- public function typeExists($index, $type)
- {
- if ($this->db->dslVersion >= 7) {
- return $this->db->head([$index, '_doc']);
- } else {
- return $this->db->head([$index, $type]);
- }
- }
- /**
- * @param string $alias
- *
- * @return bool
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- */
- public function aliasExists($alias)
- {
- $indexes = $this->getIndexesByAlias($alias);
- return !empty($indexes);
- }
- /**
- * @return array
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-retrieving
- */
- public function getAliasInfo()
- {
- $aliasInfo = $this->db->get(['_alias', '*']);
- return $aliasInfo ?: [];
- }
- /**
- * @param string $alias
- *
- * @return array
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-retrieving
- */
- public function getIndexInfoByAlias($alias)
- {
- $responseData = $this->db->get(['_alias', $alias]);
- if (empty($responseData)) {
- return [];
- }
- return $responseData;
- }
- /**
- * @param string $alias
- *
- * @return array
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- */
- public function getIndexesByAlias($alias)
- {
- return array_keys($this->getIndexInfoByAlias($alias));
- }
- /**
- * @param string $index Index that the document belongs to.
- *
- * @return array
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-retrieving
- */
- public function getIndexAliases($index)
- {
- $responseData = $this->db->get([$index, '_alias', '*']);
- if (empty($responseData)) {
- return [];
- }
- return $responseData[$index]['aliases'];
- }
- /**
- * @param string $index Index that the document belongs to.
- * @param string $alias
- * @param array $aliasParameters
- *
- * @return bool
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-adding
- */
- public function addAlias($index, $alias, $aliasParameters = [])
- {
- return (bool)$this->db->put([$index, '_alias', $alias], [], json_encode((object)$aliasParameters));
- }
- /**
- * @param string $index Index that the document belongs to.
- * @param string $alias
- *
- * @return bool
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#deleting
- */
- public function removeAlias($index, $alias)
- {
- return (bool)$this->db->delete([$index, '_alias', $alias]);
- }
- /**
- * Runs alias manipulations.
- * If you want to add alias1 to index1
- * and remove alias2 from index2 you can use following commands:
- * ~~~
- * $actions = [
- * ['add' => ['index' => 'index1', 'alias' => 'alias1']],
- * ['remove' => ['index' => 'index2', 'alias' => 'alias2']],
- * ];
- * ~~~
- * @param array $actions
- *
- * @return bool
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#indices-aliases
- */
- public function aliasActions(array $actions)
- {
- return (bool)$this->db->post(['_aliases'], [], json_encode(['actions' => $actions]));
- }
- /**
- * Change specific index level settings in real time.
- * Note that update analyzers required to [[close()]] the index first and [[open()]] it after the changes are made,
- * use [[updateAnalyzers()]] for it.
- *
- * @param string $index Index that the document belongs to.
- * @param string|array $setting
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-update-settings.html
- * @since 2.0.4
- */
- public function updateSettings($index, $setting, $options = [])
- {
- $body = $setting !== null ? (is_string($setting) ? $setting : Json::encode($setting)) : null;
- return $this->db->put([$index, '_settings'], $options, $body);
- }
- /**
- * Define new analyzers for the index.
- * For example if content analyzer hasn’t been defined on "myindex" yet
- * you can use the following commands to add it:
- *
- * ~~~
- * $setting = [
- * 'analysis' => [
- * 'analyzer' => [
- * 'ngram_analyzer_with_filter' => [
- * 'tokenizer' => 'ngram_tokenizer',
- * 'filter' => 'lowercase, snowball'
- * ],
- * ],
- * 'tokenizer' => [
- * 'ngram_tokenizer' => [
- * 'type' => 'nGram',
- * 'min_gram' => 3,
- * 'max_gram' => 10,
- * 'token_chars' => ['letter', 'digit', 'whitespace', 'punctuation', 'symbol']
- * ],
- * ],
- * ]
- * ];
- * $elasticQuery->createCommand()->updateAnalyzers('myindex', $setting);
- * ~~~
- *
- * @param string $index Index that the document belongs to.
- * @param string|array $setting
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html#update-settings-analysis
- * @since 2.0.4
- */
- public function updateAnalyzers($index, $setting, $options = [])
- {
- $this->closeIndex($index);
- $result = $this->updateSettings($index, $setting, $options);
- $this->openIndex($index);
- return $result;
- }
- // TODO https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-settings.html
- // TODO https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html
- /**
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html
- */
- public function openIndex($index)
- {
- return $this->db->post([$index, '_open']);
- }
- /**
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html
- */
- public function closeIndex($index)
- {
- return $this->db->post([$index, '_close']);
- }
- /**
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
- * @since 2.0.4
- */
- public function scroll($options = [])
- {
- $body = array_filter([
- 'scroll' => ArrayHelper::remove($options, 'scroll', null),
- 'scroll_id' => ArrayHelper::remove($options, 'scroll_id', null),
- ]);
- if (empty($body)) {
- $body = (object) [];
- }
- return $this->db->post(['_search', 'scroll'], $options, Json::encode($body));
- }
- /**
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
- * @since 2.0.4
- */
- public function clearScroll($options = [])
- {
- $body = array_filter([
- 'scroll_id' => ArrayHelper::remove($options, 'scroll_id', null),
- ]);
- if (empty($body)) {
- $body = (object) [];
- }
- return $this->db->delete(['_search', 'scroll'], $options, Json::encode($body));
- }
- /**
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html
- */
- public function getIndexStats($index = '_all')
- {
- return $this->db->get([$index, '_stats']);
- }
- /**
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html
- */
- public function getIndexRecoveryStats($index = '_all')
- {
- return $this->db->get([$index, '_recovery']);
- }
- // https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-segments.html
- /**
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clearcache.html
- */
- public function clearIndexCache($index)
- {
- return $this->db->post([$index, '_cache', 'clear']);
- }
- /**
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html
- */
- public function flushIndex($index = '_all')
- {
- return $this->db->post([$index, '_flush']);
- }
- /**
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html
- */
- public function refreshIndex($index)
- {
- return $this->db->post([$index, '_refresh']);
- }
- // TODO https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-optimize.html
- // TODO https://www.elastic.co/guide/en/elasticsearch/reference/0.90/indices-gateway-snapshot.html
- /**
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @param string|array $mapping
- * @param array $options URL options
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
- */
- public function setMapping($index, $type, $mapping, $options = [])
- {
- $body = $mapping !== null ? (is_string($mapping) ? $mapping : Json::encode($mapping)) : null;
- if ($this->db->dslVersion >= 7) {
- $endpoint = [$index, '_mapping'];
- } else {
- $endpoint = [$index, '_mapping', $type];
- }
- return $this->db->put($endpoint, $options, $body);
- }
- /**
- * @param string $index Index that the document belongs to.
- * @param string|null $type Type that the document belongs to.
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html
- */
- public function getMapping($index = '_all', $type = null)
- {
- $url = [$index, '_mapping'];
- if ($this->db->dslVersion < 7 && $type !== null) {
- $url[] = $type;
- }
- return $this->db->get($url);
- }
- /**
- * @param string $index Index that the document belongs to.
- * @param string $type
- * @return mixed
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html
- */
- // public function getFieldMapping($index, $type = '_all')
- // {
- // // TODO implement
- // return $this->db->put([$index, $type, '_mapping']);
- // }
- /**
- * @param $options
- * @param string $index Index that the document belongs to.
- * @return mixed
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html
- */
- // public function analyze($options, $index = null)
- // {
- // // TODO implement
- //// return $this->db->put([$index]);
- // }
- /**
- * @param $name
- * @param $pattern
- * @param $settings
- * @param $mappings
- * @param int $order
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
- */
- public function createTemplate($name, $pattern, $settings, $mappings, $order = 0)
- {
- $body = Json::encode([
- 'template' => $pattern,
- 'order' => $order,
- 'settings' => (object) $settings,
- 'mappings' => (object) $mappings,
- ]);
- return $this->db->put(['_template', $name], [], $body);
- }
- /**
- * @param $name
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
- */
- public function deleteTemplate($name)
- {
- return $this->db->delete(['_template', $name]);
- }
- /**
- * @param $name
- * @return mixed
- * @throws Exception
- * @throws \yii\base\InvalidConfigException
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
- */
- public function getTemplate($name)
- {
- return $this->db->get(['_template', $name]);
- }
- }
|