php - Using "terms" and "range" filters together in Elasticsearch -
i searched everywhere, none of answers met requirements. code goes this:
file 1
<?php if($year != 0) { $temp = strval($year); $term =[ "range" => [ "decidedon" => [ "gte" => $temp."-01-01", "lte" => $temp."-12-31" ] ] ]; array_push($params['body']['query']['filtered']['filter']['bool']['must'], $term); } file 2
<?php $dummy = explode(" ",$cor); $params['body']['query']['filtered']['filter']['bool']['must'] = ['terms'=> ['court' => $dummy] ]; i include them in index page @ different instances, follows
if(isset($_get['cor'])){ $cor = $_get['cor']; if(strcasecmp($cor,"all")!=0){ include 'courtfilter.php'; } } if(isset($_get['year'])){ $year = $_get['year']; if($year != 0){ include 'yearfilter.php'; } } when run query, says terms , range cannot nested together. can tell me better way without complicating program or without having write separate filter these two?
(i beginner, please pardon me if wrong or if trivial.)
you're there. in second file, need insert terms must this:
$params['body']['query']['filtered']['filter']['bool']['must'] = [['terms'=> ['court' => $dummy] ]]; ^ ^ | | add .....................and i.e. bool/must must array , assigning object/hash directly.
a better way initialize must clause before including of files (i.e. before if(isset($_get['cor']))). first initialize bool/must array this:
$params['body']['query']['filtered']['filter']['bool']['must'] = []; and in both of included files, can array_push() in file yearfilter.php
Comments
Post a Comment