请帮我。我正在使用PHP 5.5和Elasticsearch 2.1。我想在历史中排名。但是我的日期过滤器无法正常工作。
当我只在日期之间进行查询时,我得到的结果是准确的,但是当我查询日期为mont,day和hour时,却没有得到准确的结果。
例如:
http://10.0.2.15:8080/filter.php?my_date_try&my_date_lte=2017/12/3123:59:59&my_date_gte=2016/01/0100:00:00
结果不正确。
示例2:
http://10.0.2.15:8080/filter.php?my_date_try&my_date_lte=2017&my_date_gte=2016
结果正确。
我的日期映射:
$myTypeMapping['properties']['my_date']['type']='date';
$myTypeMapping['properties']['my_date']['index']='not_analyzed';
$myTypeMapping['properties']['my_date']['format']='yyyy/MM/dd HH:mm:ss';
我的日期过滤器:
unset($filter_my_date);
if(isset($_GET[my_date_try])){
$filter_my_date['range']['my_date']['lte']=$_GET['my_date_lte'];
$filter_my_date['range']['my_date']['gte']=$_GET['my_date_gte'];
$filter_my_date['range']['my_date']['format']='yyyy/MM/dd HH:mm:ss';
}
if(is_array($filter_my_date)){
$searchParams['body']['query']['bool']['must']=$filter_my_date;
}
有什么问题?
最佳答案
您的格式字符串在日期和小时之间有一个空格,您的示例网址没有:
$myTypeMapping['properties']['my_date']['format']='yyyy/MM/dd HH:mm:ss';
^
http://10.0.2.15:8080/filter.php?my_date_try&my_date_lte=2017/12/3123:59:59&my_date_gte=2016/01/0100:00:00
^ ^
关于php - Elasticsearch Php日期映射,过滤和搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35203712/