Reputation: 430
I'm ordering FOS elastica search results by datetime field in database.
The elastica.yml has this property set on mapping:
startsAt: { type: date, format: Y-m-d H:i:s }
But on populate i get this:
[Elastica\Exception\ResponseException]
MapperParsingException[mapping [soccer]]; nested: IllegalArgumentException[Invalid format: [Y-m-d H:i:s]: Illegal pattern component: i]; nested: IllegalArgumentExcept
ion[Illegal pattern component: i];
How do i specify correct format so i can search my elastica result by that datetime field?
Upvotes: 0
Views: 1563
Reputation: 430
I managed to get desired result with this...
In elastica.yml
startsAt: { "type": "date", "store": true }
In my controller action:
$query = new Query();
$queryString = new \Elastica\Query\QueryString();
$queryString->setQuery('*'.$request->query->get('search').'*');
$query->setQuery($queryString);
$query->addSort(array('startsAt' => array('order' => 'desc')));
$results = $finder->findPaginated(
$query,
array(
'from' => ($request->query->get('page', 1) - 1) * $limit,
'limit' => $limit,
)
);
Upvotes: 2