Elasticsearch Range Filter


(Hilal) #1

Hi,
I am using PHP 5.1, Mysql and Elasticsearch 2.1.
I indexed my datas to Elasticsearch from Mysql .
I am doing filter and query now. I have date field.
I want to do date range filter and query.

My codes:

unset($filter_date);
if(isset($_GET['date_gte'])){
$filter_date['range']['date']['gte']=$_GET['date_gte'];
$filter_date['range']['date']['lte']=$_GET['date_lte'];
}
if(is_array($filter_date)){
$searchParams['body']['query']=$filter_datei;
}

My query on URL:
10.0.2.15:8080/filters.php?date_gte=2013-31-01 00:00:00&date_lte=2015-31-01

Unfortunately it dosen't return results. Please help me


Date format incorrect results
(David Pilato) #2

Does it work with date_gte=2013-01-01&date_lte=2015-01-01?

Make sure your date format is the same as defined in the mapping.


(Hilal) #3

Date mapping code:

$myTypeMapping['properties']['date']['type']='date';
$myTypeMapping['properties']['date']['index']='not_analyzed';


(David Pilato) #4

Not the same format as the query you sent. Read the doc about date mapping and its default format.


(Hilal) #5

I read.

$myTypeMapping['properties']['date']['type']='date';
$myTypeMapping['properties']['date']['index']='analyzed';
$myTypeMapping['properties']['date']['format']='yyyy-MM-dd';

Is it true?


(David Pilato) #6

Try with:


(Hilal) #7

ok It is done Thank you


(system) #8