Yii2 elasticSearch 多值查询 和 查询数组字段

Yii2 elasticSearch 多值查询的例子,相当于关系型数据库的in查询

$should = [];
if(is_array($customers) && !empty($customers)){
  foreach($customers as $one){
    $should[] = ['term' => ['customer_id' => $one['customer_id']]];
  }
}
$filter_arr['bool']['should'] = $should;
$result = $obj::find()->filter($filter_arr)
    ->query($query_arr)
    ->asArray()
    ->limit(0)
    ->offset(33)
    ->all();
$data = BaseArrayHelper::getColumn($result, '_source');

查询数组字段,$filter的定义如下:

$filter_arr = [
        'bool' => [
          'must' => [
            ['term' => ['emails' => $email],]
          ]
        ],
      ];

 

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注