CakePHP 3返回亮点弹性搜索

时间:2015-10-20 14:25:54

标签: cakephp elasticsearch cakephp-3.0 elasticsearch-plugin

我尝试从搜索中获取突出显示,但结果没有突出显示

我正在使用此插件:http://book.cakephp.org/3.0/en/elasticsearch.html#searching-indexed-documents

我的代码:

 public function pesquisaIndice($searchText = null){

     $this->loadModel('BooksI', 'Elastic');

    $query = $this->BooksI->find()->limit(100)->highlight(['fields'=> ['number_of_fragments'=>20]]);

    $query->where(function ($builder) {

      return $builder->query(
                 [
                   'query_string' =>
                       [
                           'query'=> ' melhor',
                           'default_operator' =>'and'
                         ],
               ]
       );
    });


    var_dump($query);


 }

1 个答案:

答案 0 :(得分:0)

在命令行中我可以...但是使用这个插件我不能

curl -XGET "http://localhost:9200/my_apps_index/_search?pretty=true" -d '{
    "query": {
        "query_string": {
            "query": "melhor"
        }
    },
    "highlight": {
        "pre_tags": ["<b>"],
        "post_tags": ["</b>"],
        "fields": {
            "content": {"number_of_fragments": 20}
        }
    }    
}'