I am trying to find out the names between a time period.
But the problem is when i try to run it
first-- it returns the selected names value second -- it returns data between that period.
Now what i want to do is that, i want to search name between a time period.
For explaining it more, suppose we have select a name "john", and select a date 2/08/2015 to 27/08/2015, so it should return all the names between that time period.
But it is returning the names of john and than searching for other documents between that period, where is should also take the name "John" when searching the date !
How to solve this problem !
$name = $request->request->get('name');
$strat_date = $request->request->get('strat_date');
$end_date = $request->request->get('end_date');
$params = array(
'index' => "myIndex",
'type' => "myType",
'body' => array(
'query' => array(
'bool' => array(
'must' => array(
// empty should clause for starters
)
)
)
)
);
// add each constraint in turn depending on whether the param is specified
if (!empty($sourceFilter)) {
$params['body']['query']['bool']['must'] = array(
'query_string' => array(
'default_field' => 'name',
'query' => implode(" ", $name)
)
);
}
if (!empty($end_date)) {
$params['body']['query']['bool']['must']['range'] = array(
'datehistory' => array(
"from" => $strat_date,
"to" => $end_date
)
);
}
// special case if none is present, just match everything
if (count($params['body']['query']['bool']['must']) == 0) {
$params['body']['query'] = array(
'match_all' => array()
);
}
$docs = $client->search($params);
But at always return the an error like this ----
{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[agEfJ6ltSJmlec3gpnPg3g][myIndex][1]: SearchParseException[[myIndex][1]: from[-1],size[-1]: Parse Failure [Failed to parse name [{\"query\":{\"bool\":{\"must\":{\"query_string\":{\"default_field\":\"name\",\"query\":\"john.se\"},\"range\":{\"datehistory\":{\"from\":1438207200,\"to\":1440626400}}}}}}]]]; nested: QueryParsingException[[myIndex] No query registered for [datehistory]]; }]","status":400}