Builder for ElasticSearch query DSL in Yii2 (or standalone) Builder for ElasticSearch query DSL in Yii2 (or standalone) elasticsearch elasticsearch

Builder for ElasticSearch query DSL in Yii2 (or standalone)


If you intend to build for version 1.6 of elastic, I have created a query builder for my company and published it here

You will use it as a standalone query builder, and at the end you will need to get the final query array and pass it to the query executer.

To install it, you can simply use composer composer require itvisionsy/php-es-orm or download the zipped version here.

The link above contains some examples, and here is a copy:

//build the query using different methods$query = \ItvisionSy\EsMapper\QueryBuilder::make()            ->where('key1','some value') //term clause            ->where('key2',$intValue,'>') //range clause            ->where('key3','value','!=') //must_not term clause            ->where('key4', ['value1','value2']) //terms clause            ->where('email', '@hotmail.com', '*=') //wildcard search for all @hotmail.com emails            ->sort('key1','asc') //first sort option            ->sort('key2',['order'=>'asc','mode'=>'avg']) //second sort option            ->from(20)->size(20) //results from 20 to 39            ->toArray();//modify the query as you need$query['aggs']=['company'=>['terms'=>['field'=>'company']]];//then execute it against a type query$result = TypeQuery::query($query);//i am not sure about Yii way to execute, according to the question, it should be:$result = ElasticModel::find()->query($query); 

The package also include a simple ElasticSearch ORM class which maybe useful for you. Take a look at it here.

Hope this helps you...