It is an yii-1.x extension for performing ElasticSearch queries. This extension is based on Official low-level client for ElasticSearch
Requirements ¶
- PHP 7.0 or higher
Installation ¶
- Download the extension
- Copy elasticSearch extension to your project extension direcory
- Add components to main.php
'es' => [
'class' => 'application.extensions.elasticSearch.ElasticSearch',
'host' => '127.0.0.1:9200',
// Array of index types. Array keys indicate the name of indexes
'es_index_type' => [
'my_index' => 'my_type',
'my_index2' => 'my_type2',
'my_index3' => 'my_type2',
// list all indexes and types [key value pare]
]
]
Usage ¶
Query by ID
$response = Yii::app()->es->getById('my_index', 'my_id');
Output look like
Array
(
[_index] => my_index
[_type] => my_type
[_id] => my_id
[_version] => 1
[found] => 1
[_source] => Array
(
[id] => my_id
.....
)
)
Get by query
$queryBody = [];
$queryBody['_source'] = 'field1, field2, field3'; // An example of selected fields
$queryBody['body'] = [
'query' => [
'bool' => [
'must' => [
'bool' => [
'should' => [
[ 'match' => [ 'condition_field_name' => "condition_value" ] ]
]
]
]
]
]
];
$response = Yii::app()->es->getByQuery('my_index', $queryBody);
Query as per official documentation
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id'
];
$response = Yii::app()->es->getClientInstance()->get($params);
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.