diff --git a/Mapping/DocumentParser.php b/Mapping/DocumentParser.php index 7b073135..d73bae70 100644 --- a/Mapping/DocumentParser.php +++ b/Mapping/DocumentParser.php @@ -378,7 +378,7 @@ private function getDocumentType($document) $reflectionClass = new \ReflectionClass($namespace); $document = $this->getDocumentAnnotationData($reflectionClass); - return empty($document->type) ? $reflectionClass->getShortName() : $document->type; + return empty($document->type) ? Caser::snake($reflectionClass->getShortName()) : $document->type; } /** diff --git a/Profiler/ElasticsearchProfiler.php b/Profiler/ElasticsearchProfiler.php index eaa596e0..85bde2fb 100644 --- a/Profiler/ElasticsearchProfiler.php +++ b/Profiler/ElasticsearchProfiler.php @@ -173,7 +173,7 @@ private function handleRecords($route, $records) private function addQuery($route, $record, $queryBody) { parse_str(parse_url($record['context']['uri'], PHP_URL_QUERY), $httpParameters); - $body = json_decode(trim($queryBody, " '\r\t\n"), true); + $body = json_decode(trim($queryBody, " '\r\t\n")); $this->queries[$route][] = array_merge( [ 'body' => $body !== null ? json_encode($body, JSON_PRETTY_PRINT) : '', diff --git a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php index 7869ecb6..086477b7 100644 --- a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php +++ b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php @@ -13,6 +13,8 @@ use ONGR\ElasticsearchBundle\Profiler\ElasticsearchProfiler; use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\BarBundle\Document\Product; +use ONGR\ElasticsearchDSL\Aggregation\GlobalAggregation; +use ONGR\ElasticsearchDSL\Query\MatchAllQuery; use ONGR\ElasticsearchDSL\Query\TermQuery; use ONGR\ElasticsearchBundle\Service\Repository; use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase; @@ -161,4 +163,22 @@ private function getCollector() return $collector; } + + public function testMatchAllQuery() + { + $manager = $this->getManager(); + + $repository = $manager->getRepository('AcmeBarBundle:Product'); + $search = $repository + ->createSearch() + ->addAggregation(new GlobalAggregation('g')); + $repository->execute($search); + + $queries = $this->getCollector()->getQueries(); + $lastQuery = end($queries[ElasticsearchProfiler::UNDEFINED_ROUTE]); + $this->checkQueryParameters($lastQuery); + $lastQuery['body'] = trim(preg_replace('/\s+/', '', $lastQuery['body'])); + + $this->assertEquals('{"aggregations":{"g":{"global":{}}}}', $lastQuery['body']); + } }