# Class yii\elasticsearch\Command

Inheritance | yii\elasticsearch\Command » yii\base\Component » yii\base\BaseObject
Implements | yii\base\Configurable
Available since version | 2.0
Source Code | https://github.com/yiisoft/yii2-elasticsearch/blob/master/Command.php

The Command class implements the API for accessing the Elasticsearch REST API.

Check the Elasticsearch guide for details on these commands.

## Public Properties

Hide inherited properties

Property | Type | Description | Defined By
--- | --- | --- | ---
$aliasInfo | array |  | yii\elasticsearch\Command
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component. This property is read-only. | yii\base\Component
$db | yii\elasticsearch\Connection |  | yii\elasticsearch\Command
$index | string|array | The indexes to execute the query on. | yii\elasticsearch\Command
$indexRecoveryStats | mixed |  | yii\elasticsearch\Command
$indexStats | mixed |  | yii\elasticsearch\Command
$mapping | mixed |  | yii\elasticsearch\Command
$options | array | Options to be appended to the query URL, such as "search_type" for search or "timeout" for delete | yii\elasticsearch\Command
$queryParts | array | List of arrays or json strings that become parts of a query | yii\elasticsearch\Command
$type | string|array | The types to execute the query on. | yii\elasticsearch\Command

## Public Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
__call() | Calls the named method which is not a class method. | yii\base\Component
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component
__construct() | Constructor. | yii\base\BaseObject
__get() | Returns the value of a component property. | yii\base\Component
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component
__set() | Sets the value of a component property. | yii\base\Component
__unset() | Sets a component property to be null. | yii\base\Component
addAlias() |  | yii\elasticsearch\Command
aliasActions() | Runs alias manipulations. | yii\elasticsearch\Command
aliasExists() |  | yii\elasticsearch\Command
attachBehavior() | Attaches a behavior to this component. | yii\base\Component
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component
className() | Returns the fully qualified name of this class. | yii\base\BaseObject
clearIndexCache() |  | yii\elasticsearch\Command
clearScroll() |  | yii\elasticsearch\Command
closeIndex() |  | yii\elasticsearch\Command
createIndex() | Creates an index | yii\elasticsearch\Command
createTemplate() |  | yii\elasticsearch\Command
delete() | Deletes a document from the index | yii\elasticsearch\Command
deleteAllIndexes() | Deletes all indexes | yii\elasticsearch\Command
deleteByQuery() | Sends a request to the delete by query | yii\elasticsearch\Command
deleteIndex() | Deletes an index | yii\elasticsearch\Command
deleteTemplate() |  | yii\elasticsearch\Command
detachBehavior() | Detaches a behavior from the component. | yii\base\Component
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component
exists() | Gets a document from the index | yii\elasticsearch\Command
flushIndex() |  | yii\elasticsearch\Command
get() | Gets a document from the index | yii\elasticsearch\Command
getAliasInfo() |  | yii\elasticsearch\Command
getBehavior() | Returns the named behavior object. | yii\base\Component
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component
getIndexAliases() |  | yii\elasticsearch\Command
getIndexInfoByAlias() |  | yii\elasticsearch\Command
getIndexRecoveryStats() |  | yii\elasticsearch\Command
getIndexStats() |  | yii\elasticsearch\Command
getIndexesByAlias() |  | yii\elasticsearch\Command
getMapping() |  | yii\elasticsearch\Command
getSource() | Gets a documents _source from the index (>=v0.90.1) | yii\elasticsearch\Command
getTemplate() |  | yii\elasticsearch\Command
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component
indexExists() | Checks whether an index exists | yii\elasticsearch\Command
init() | Initializes the object. | yii\base\BaseObject
insert() | Inserts a document into an index | yii\elasticsearch\Command
mget() | Gets multiple documents from the index | yii\elasticsearch\Command
off() | Detaches an existing event handler from this component. | yii\base\Component
on() | Attaches an event handler to an event. | yii\base\Component
openIndex() |  | yii\elasticsearch\Command
refreshIndex() |  | yii\elasticsearch\Command
removeAlias() |  | yii\elasticsearch\Command
scroll() |  | yii\elasticsearch\Command
search() | Sends a request to the _search API and returns the result | yii\elasticsearch\Command
setMapping() |  | yii\elasticsearch\Command
suggest() | Sends a suggest request to the _search API and returns the result | yii\elasticsearch\Command
trigger() | Triggers an event. | yii\base\Component
typeExists() |  | yii\elasticsearch\Command
update() | Updates a document | yii\elasticsearch\Command
updateAnalyzers() | Define new analyzers for the index. | yii\elasticsearch\Command
updateSettings() | Change specific index level settings in real time. | yii\elasticsearch\Command

## Property Details

$aliasInfo public read-only property
public array getAliasInfo ( )
$db public property
public yii\elasticsearch\Connection $db = null
$index public property

The indexes to execute the query on. Defaults to null meaning all indexes

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-multi-index-type.

public string|array $index = null
$indexRecoveryStats public read-only property
public mixed getIndexRecoveryStats ( $index = '_all' )
$indexStats public read-only property
public mixed getIndexStats ( $index = '_all' )
$mapping public read-only property
public mixed getMapping ( $index = '_all', $type = null )
$options public property

Options to be appended to the query URL, such as "search_type" for search or "timeout" for delete

public array $options = []
$queryParts public property

List of arrays or json strings that become parts of a query

public array $queryParts = null
$type public property

The types to execute the query on. Defaults to null meaning all types

public string|array $type = null

## Method Details

addAlias() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-adding.

public boolean addAlias ( $index, $alias, $aliasParameters = [] )
$index |  |
$alias |  |
$aliasParameters | array |

aliasActions() public method

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']],

]; ~~~

See also https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#indices-aliases.

public boolean aliasActions ( array $actions )
$actions | array |

aliasExists() public method

public boolean aliasExists ( $alias )
$alias | string |

clearIndexCache() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clearcache.html.

public mixed clearIndexCache ( $index )
$index |  |

clearScroll() public method (available since version 2.0.4)

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html.

public mixed clearScroll ( $options = [] )
$options | array |

closeIndex() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html.

public mixed closeIndex ( $index )
$index |  |

createIndex() public method

Creates an index

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html.

public mixed createIndex ( $index, $configuration = null )
$index |  |
$configuration | array |

createTemplate() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html.

public mixed createTemplate ( $name, $pattern, $settings, $mappings, $order = 0 )
$name |  |
$pattern |  |
$settings |  |
$mappings |  |
$order | integer |

delete() public method

Deletes a document from the index

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html.

public mixed delete ( $index, $type, $id, $options = [] )
$index |  |
$type |  |
$id |  |
$options | array |

deleteAllIndexes() public method

Deletes all indexes

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html.

public mixed deleteAllIndexes ( )

deleteByQuery() public method

Sends a request to the delete by query

public mixed deleteByQuery ( $options = [] )
$options | array |

deleteIndex() public method

Deletes an index

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html.

public mixed deleteIndex ( $index )
$index |  |

deleteTemplate() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html.

public mixed deleteTemplate ( $name )
$name |  |

exists() public method

Gets a document from the index

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html.

public mixed exists ( $index, $type, $id )
$index |  |
$type |  |
$id |  |

flushIndex() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html.

public mixed flushIndex ( $index = '_all' )
$index |  |

get() public method

Gets a document from the index

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html.

public mixed get ( $index, $type, $id, $options = [] )
$index |  |
$type |  |
$id |  |
$options | array |

getAliasInfo() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-retrieving.

public array getAliasInfo ( )

getIndexAliases() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-retrieving.

public array getIndexAliases ( $index )
$index | string |

getIndexInfoByAlias() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-retrieving.

public array getIndexInfoByAlias ( $alias )
$alias | string |

getIndexRecoveryStats() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html.

public mixed getIndexRecoveryStats ( $index = '_all' )
$index |  |

getIndexStats() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html.

public mixed getIndexStats ( $index = '_all' )
$index |  |

getIndexesByAlias() public method

public array getIndexesByAlias ( $alias )
$alias | string |

getMapping() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html.

public mixed getMapping ( $index = '_all', $type = null )
$index | string |
$type | string |

getSource() public method

Gets a documents _source from the index (>=v0.90.1)

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source.

public mixed getSource ( $index, $type, $id )
$index |  |
$type |  |
$id |  |

getTemplate() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html.

public mixed getTemplate ( $name )
$name |  |

indexExists() public method

Checks whether an index exists

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html.

public mixed indexExists ( $index )
$index |  |

insert() public method

Inserts a document into an index

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html.

public mixed insert ( $index, $type, $data, $id = null, $options = [] )
$index | string |
$type | string |
$data | string|array | Json string or array of data to store
$id | null | The documents id. If not specified Id will be automatically chosen
$options | array |

mget() public method

Gets multiple documents from the index

TODO allow specifying type and index + fields

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html.

public mixed mget ( $index, $type, $ids, $options = [] )
$index |  |
$type |  |
$ids |  |
$options | array |

openIndex() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html.

public mixed openIndex ( $index )
$index |  |

refreshIndex() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html.

public mixed refreshIndex ( $index )
$index |  |

removeAlias() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#deleting.

public boolean removeAlias ( $index, $alias )
$index | string |
$alias | string |

scroll() public method (available since version 2.0.4)

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html.

public mixed scroll ( $options = [] )
$options | array |

search() public method

Sends a request to the _search API and returns the result

public mixed search ( $options = [] )
$options | array |

setMapping() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html.

public mixed setMapping ( $index, $type, $mapping, $options = [] )
$index | string |
$type | string |
$mapping | string|array |
$options | array |

suggest() public method

Sends a suggest request to the _search API and returns the result

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html.

public mixed suggest ( $suggester, $options = [] )
$suggester | string|array | The suggester body
$options | array |

typeExists() public method

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-types-exists.html.

public mixed typeExists ( $index, $type )
$index |  |
$type |  |

update() public method

Updates a document

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html.

public mixed update ( $index, $type, $id, $data, $options = [] )
$index |  |
$type |  |
$id |  |
$data |  |
$options | array |

updateAnalyzers() public method (available since version 2.0.4)

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);

See also https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html#update-settings-analysis.

public mixed updateAnalyzers ( $index, $setting, $options = [] )
$index | string |
$setting | string|array |
$options | array | URL options

updateSettings() public method (available since version 2.0.4)

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.

See also http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-update-settings.html.

public mixed updateSettings ( $index, $setting, $options = [] )
$index | string |
$setting | string|array |
$options | array | URL options