如何进行如下查询
http://localhost:9200/index/businesses/_search?q=services在Cakephp3 ElasticSearch中
我试过了
$this->Businesses->find('all')->where(['*'=>'services']);然而,我没有得到任何结果。
发布于 2016-03-20 19:24:27
更准确的答案是使用构建器
$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']);发布于 2016-03-20 03:08:44
不知道您在问什么,但是where(['*'=>'services'])中的星号应该是表模式/数据库中的列名。
另一个常见的问题是,find()的结果并非设计为查询的结果。请参阅我对Cake PHP 3 needs limit option for find all method和CakePHP 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;
}https://stackoverflow.com/questions/36101949
复制相似问题