如何在Yii2 Elasticsearch中使用活动查询过滤数组字段类型?

时间:2018-06-22 19:24:28

标签: elasticsearch activerecord yii2

我正在使用Elasticsearch,并且我具有数组类型的给定字段,即:

cities = [ 15, 17, 23, 19 ]

如何使用\ yii \ elasticsearch \ ActiveRecord,我可以过滤以下内容:

[Registry contains city 17]

会是这样吗?

// Example model
class ESModel extends \yii\elasticsearch\ActiveRecord {
    public static properties() {
        'cities'
    ]
}

// Saving the example registry
$model = new ESModel();
$model->cities = [ 15, 17, 23, 19 ];
$model->save();

这是解决方案

// Find the registry, the below line works!
$registry = ESModel::find()->where(['IN', 'cities', 17])->one()

谢谢。

0 个答案:

没有答案