я пытаюсь найти диапазон дат с FOSElasticaBundle
$query = new MatchAll();
$now = date('Y-m-d');
$rangeLower = new Filtered(
$query,
new Range('visibleFrom', array(
'gte' => $now
))
);$rangeUpper = new Filtered(
$query,
new Range('visibleTo', array(
'lte' => $now
))
);
$query = new \Elastica\Query($rangeUpper);$boolFilter = new \Elastica\Filter\Bool();
$boolFilter->addMust(
new \Elastica\Filter\Terms('place_id', array(
$place_id
))
);
$query->setFilter($boolFilter);//$finder = $this->container->get('fos_elastica.finder.place.event');$res = $this->finder->find($query,10);
но это не работает
print_r($query->getQuery());Elastica\Query\Filtered Object
(
[_params:protected] => Array
(
[query] => Elastica\Query\MatchAll Object
(
[_params:protected] => stdClass Object
(
)
[_rawParams:protected] => Array
(
)
)
[filter] => Elastica\Filter\Range Object
(
[_fields:protected] => Array
(
[visibleTo] => Array
(
[lte] => 2016-01-05
)
)
[_params:protected] => Array
(
[visibleTo] => Array
(
[lte] => 2016-01-05
)
)
[_rawParams:protected] => Array
(
)
)
)
[_rawParams:protected] => Array
(
)
)
я хочу найти объект с visibleFrom> $ сейчас и visibleTo < $ сейчас и place_id = $ place_id
вот конфиг маппинга
event:
mappings:
id:
type : integer
place_id:
type : integer
visibleFrom:
type: date
visibleTo:
type: date
dateStart:
type: date
dateEnd:
type: date
persistence:
driver: orm
model: Place\CalendarBundle\Entity\Event
finder: ~
provider: ~
listener: ~
$ filters-> addMust (new \ Elastica \ Filter \ NumericRange (‘publ_at’,
массив (‘lte’ => date (‘c’),)));
Вы можете попробовать это в вашем config.yml:
fos_elastica:
clients:
default: { host: 'localhost', port: '9201' }
indexes:
prefix_user:
types:
user:
properties:
username: ~
lastLogin:
type: "date"persistence:
driver: orm
model: AppBundle\Entity\User
provider: ~
finder: ~
и добавьте param в свой запрос:
<?php
namespace AppBundle\Model\Services\ElasticSearch;
use Elasticsearch\ClientBuilder;
/**
* Class ElasticSearchManager
*
* Manager class to interact with the elasticsearch instance
*
* @package AppBundle\Model\Services\ElasticSearch
*/
class ElasticSearchManager
{
/**
* Find all user indexed
*
* @return array colors
*/
public function findUsers()
{
$results = [];
$params = [
'index' => 'prefix_user',
'type' => 'user',
'from' => 0,
'size' => 1000,
'body' => [
'query' => [
'bool' => [
'filter' => [
"range" => [
"lastLogin" => [
"gte" => "02/05/2018",
"lte" => "2050",
"format" => "dd/MM/yyyy||yyyy"]
]
]
]
],
'sort' => [
'_id' => [
'order' => 'asc'
]
]
]
];
$results = $this->client->search($params);
return $results;
}
}
документация Вот