elasticsearch,foselasticabundle,Symfony,elasticsearch,Foselasticabundle" /> elasticsearch,foselasticabundle,Symfony,elasticsearch,Foselasticabundle" />

Symfony Foselasticabundle:方法返回空结果

Symfony Foselasticabundle:方法返回空结果,symfony,elasticsearch,foselasticabundle,Symfony,elasticsearch,Foselasticabundle,我使用Elasticsearch和Foselasticabundle在我的Symfony应用程序中搜索,但它返回空结果。 这是我的配置和搜索方法: foselasticbunde.yml: indexes: search: finder: ~ client: default types: course: mappings:

我使用Elasticsearch和Foselasticabundle在我的Symfony应用程序中搜索,但它返回空结果。 这是我的配置和搜索方法:

foselasticbunde.yml:

  indexes:
       search:
           finder: ~
           client: default
           types:
               course:
                   mappings:
                       id: ~
                       title: ~

                   persistence:
                       driver: orm
                       model: AppBundle\Entity\Course
                       finder: ~
                       provider: ~
                       listener: ~
SearchController.php

 public function elasticSearchAction(Request $request)
    {
        $query = $request->get('q');
        $finder = $this->container->get('fos_elastica.finder.search.course');
        $results = $finder->find($query);
        return new JsonResponse($results);
    }
但它会返回这个空结果:

[{},{},{},{},{},{},{},{},{},{}]

问题是什么?我如何解决它?

结果是一个对象数组,我更改了代码:

public function elaSearchAction(Request $request)
{
    $query = $request->get('q');

    $finder = $this->container->get('fos_elastica.finder.search.course');
    $results = $finder->find($query);

    $data = array();
    foreach ($results as $course){
        $data[] = array(
            'id' => $course->getId(),
            'title' => $course->getTitle(),
            'description' => $course->getDescription(),
        );
    }

    return new JsonResponse($data);
}

您填充索引了吗?是的,我使用了以下命令:
php应用程序/console fos:elastica:populate
尝试检查$query是否为空。回音$query@AmiraBedhiafi不,不是空的。