ongr-io/ElasticsearchBundle — pull request #20 by ivannis (2014-11-07 21:13:34+00:00)
Title: added the ability to run raw query

This feature allow you to execute rawQuery directly from the library [elasticsearch-php](https://github.com/elasticsearch/elasticsearch-php).

Sometimes we need to do some complex queries and would be nice that we could run it for an easy way.

For example
````php
$manager = $this->get("es.manager");
$repository = $manager->getRepository('AcmeDemoBundle:City');

$latitude = 40.00;
$longitude = -2.5;
$distance = 12;
$me = 'someId';

$query = array(
"size" => $limit,
"sort" => array(
array(
"_geo_distance" => array(
"location" => array(
"lat" => $latitude,
"lon" => $longitude
),
"order" => "asc",
"unit" => "km"
)
)
),
'query' => array(
'filtered' => array(
'query' => array(
'match_all' => array()
),
'filter' => array(
'and' => array(
'filters' => array(
array(
'geo_distance' => array(
'distance' => $distance . 'km',
'location' => array(
'lat' => $latitude,
'lon' => $longitude
)
)
),
array(
'not' => array(
'filter' => array(
'term' => array(
'_id' => $me
)
)
)
)
)
)
)
)
)
);

$nearbyCities = $repository->search($query);

````

You can also run the query as a string json
````php
$manager = $this->get("es.manager");
$repository = $manager->getRepository('AcmeDemoBundle:City');

$query = '{
"query": {
"term" : {
"slug" : "some-slug"
}
}
}'

$someCity = $repository->search($query);
````