Laravel5.8 使用 Elasticsearch 做引擎,scout 全文搜索报错:Unsupported operand types


Laravel5.8 使用 Elasticsearch 做引擎,scout 全文搜索报错:Unsupported operand types
提示分页错误

/home/vagrant/code/social-contact/vendor/tamayo/laravel-scout-elastic/src/ElasticsearchEngine.php
        ]));
    }
 
    /**
     * Perform the given search on the engine.
     *
     * @param  Builder  $builder
     * @param  int  $perPage
     * @param  int  $page
     * @return mixed
     */
    public function paginate(Builder $builder, $perPage, $page)
    {
        $result = $this->performSearch($builder, [
            'numericFilters' => $this->filters($builder),
            'from' => (($page * $perPage) - $perPage),
            'size' => $perPage,
        ]);
 
       $result['nbPages'] = $result['hits']['total']/$perPage;
 
        return $result;
    }
 
    /**
     * Perform the given search on the engine.
     *
     * @param  Builder  $builder
     * @param  array  $options
     * @return mixed
     */
    protected function performSearch(Builder $builder, array $options = [])
    {
        $params = [
            'index' => $this->index,
            'type' => $builder->index ?: $builder->model->searchableAs(),
            'body' => [
                'query' => [
                    'bool' => [
                        'must' => [['query_string' => [ 'query' => "*{$builder->query}*"]]]
Arguments
"Unsupported operand types"

如图:

解决办法:
我用的elasticearch 7.2.0版本,经过排查怀疑是elasticsearch版本太高的原因,将es与ik插件都换成6.2.4版本, OK这样就解决了。

  1. linux/Ubuntu系统下elasticsearch的安装教程
  2. elasticsearch 安装IK分词插件

定制homestead版

  1. windows 10 vagrant@定制版本homestead 开启Elasticsearch
  2. 定制版Homestead Elasticsearch 6 启动成功后,手动安装IK插件
阅读 84

Comments