问题
I want to index of my mysql database with elasticsearch. My datas is about datetime. I indexed my datas. I am using PHP 5.5 and Elasticsearch 2.1 and Mysql.
My codes for mapping:
$myTypeMapping['properties']['$date']['type']='date';
$myTypeMapping['properties']['$date']['index']='not_analyzed';
$myTypeMapping['properties']['$date']['format']='yyyy-MM-DD HH:mm:ss';
My codes for filter and query: (gte, lte,range query)
unset($filter_date);
if(isset($GET['dategte'])){
$filter_date['range']['date']['gte']=(($GET['dategte']));
$filter_date['range']['date']['lte']=(($GET['datelte']));
}
if(is_array($filter_date)){
$searchParams['body']['query']['filtered']['filter']['and'][]=$filter_date;
}
My query: (between [2016-01-01 00:00:00]-[2017-12-31 23:59:59])
http://10.0.2.15:8080/filter.php?date_gte=2016-01-01 00:00:00&date_lte=2017-12-31 23:59:59
-->The fact that needs to find 38 results.
-->But showing only 1 results-> 2017-07-03 14:00:00,
-->Records in 2016, not shown.
If I change the query as follows: (2016-2017)
http://10.0.2.15:8080/filter.php?date_gte=2016&date_lte=2017
-->38 records coming. That's true. However I would like to query as day month year hours minutes.
Also another query: ([2015-01-01 00:00:00]-[2017-12-31 23:59:59])
http://10.0.2.15:8080/filter.php?date_gte=2015-01-01 00:00:00&date_lte=2017-12-31 23:59:59
-->38 records coming. It is not correct. Actually, There are 100 registration 2015 between 2017.
I think the problem is about php. But ı am not sure. What is the problem?Please help me.
来源:https://stackoverflow.com/questions/35288526/elasticsearch-php-mysql-datetime-filter-and-query