当前位置: 代码迷 >> 综合 >> Elasticsearch 随机查询(抽样查询)PHP 使用方法
  详细解决方案

Elasticsearch 随机查询(抽样查询)PHP 使用方法

热度:79   发布时间:2023-12-05 08:24:38.0
    public function getTopicList($query,$size=1000,$page=0,$field=null,$IS_RANDOM){$params = ['size'      => $size,'index'     => 'mokao_bank_2','type'      => 'mokao_bank_2','body'      => ['query' => $query]];//查询条件query如下//$query = [//    'bool' => [//        'must' => [//            ['match' => [ 'subject_category_id' => $subject ]],//            ['match' => [ 'subject_type_id'     => $topicType ]],//            ['match' => [ 'is_hid'              => 0 ]],//            ['match' => [ 'is_del'              => 0 ]],//        ]//    ]//];if($field){$params['_source'] = $field;}if($page > 0){$from = ($page - 1) * $size;$params['from'] = $from;}$params['body']['sort']=['_id'   => ['order' => 'asc']];//抽样查询时排序替换为如下条件if($IS_RANDOM){$params['body']['sort'] = ['_script' => ['script' => 'Math.random()','type'   => 'number','order'  => 'asc']];}$return = $this->client->search($params);return $return['hits']['hits'];}

 

  相关解决方案