如果您打算为 1.6 版的 elastic 构建,我已经为我的公司创建了一个查询构建器并在此处发布
您将使用它作为独立的查询构建器,最后您需要获取最终的查询数组并将其传递给查询执行器。
要安装它,您可以简单地使用 composer或在此处composer require itvisionsy/php-es-orm
下载压缩版本。
上面的链接包含一些示例,这里是一个副本:
//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);
该软件包还包括一个简单的 ElasticSearch ORM 类,它可能对您有用。看看这里。
希望这可以帮助你...