Cakephp3 ElasticSearch查询Q

时间:2016-03-19 12:49:36

标签: php cakephp elasticsearch orm cakephp-3.0

如何进行类似

的查询
http://localhost:9200/index/businesses/_search?q=services
Cakephp3 ElasticSearch中的

我试过了

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

但是我没有结果。

2 个答案:

答案 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']);

答案 1 :(得分:0)

不确定您要问的是什么,但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;
}