【问题标题】:Cakephp3 ElasticSearch Query QCakephp3 ElasticSearch查询Q
【发布时间】:2016-03-19 12:49:36
【问题描述】:

我如何进行类似的查询

http://localhost:9200/index/businesses/_search?q=services

在 Cakephp3 弹性搜索中

我试过了

$this->Businesses->find('all')->where(['*'=>'services']);

但是我没有得到任何结果。

【问题讨论】:

  • TLDR;如何在不使用 CakephpES 指定列的情况下从 ES 数据源中搜索文档?

标签: php cakephp elasticsearch orm cakephp-3.0


【解决方案1】:

更准确的答案是使用构建器

    $q = 'services'; 
    $businesses = $this->Businesses->find('all')->where(function ($builder) use($q) {
            return $builder->query(new \Elastica\Query\SimpleQueryString($q));
        });

_all 键可能会解决问题

$this->Businesses->find('all')->where(['_all'=>'services']);

【讨论】:

    【解决方案2】:

    不确定您要问什么,但where(['*'=>'services']) 中的星号应该是您的表架构/数据库中的列名。

    另一个常见问题是find() 的结果不是设计查询的结果。请参阅我对Cake PHP 3 needs limit option for find all methodCakePHP 3 Cookbook: ElasticSearch — Searching Indexed Documents 的回答:

    $query = $this->Articles->find()
        ->where([
            'title' => 'special',
            'or' => [
                'tags in' => ['cake', 'php'],
                'tags not in' => ['c#', 'java']
            ]
        ]);
    
    // The query returns multiple rows which you can loop through
    //  or alternatively you can call $query->all(); to get the object
    //                                $query->toArray(); to get the array
    foreach ($query as $article) {
        echo $article->title;
    }
    

    【讨论】:

    • ElasticSearch 允许您在不指定列的情况下搜索文档。我想在不指定列的情况下进行搜索。
    猜你喜欢
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多