yii-elastic-search Yii 1.x extension for ElasticSearch

  1. Requirements
  2. Installation
  3. Usage
  4. Resources

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

  1. Download the extension
  2. Copy elasticSearch extension to your project extension direcory
  3. 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);

Resources

2 0
2 followers
0 downloads
Yii Version: 1.1.*
License: MIT
Category: Database
Developed by: mh2k9
Created on: Apr 17, 2018
Last updated: 6 years ago
Github Repository

Downloads

show all

Related Extensions