elasticsearch - Elastica filter not working -


i testing out elastica , elastic search. trying add filter query returns results city location. returning empty. i've tried filter username, , on , returns empty, seem understanding isn't quite correct. here's code analyse, map, search filter

    $elasticaindex = $elasticaclient->getindex('users');     // create index new     $elasticaindex->create(             array(         'analysis' => array(             'analyzer' => array(                 'indexanalyzer' => array(                     'type' => 'custom',                     'tokenizer' => 'standard',                     'filter' => array('lowercase', 'lb_ngram')                 ),                 'searchanalyzer' => array(                     'type' => 'custom',                     'tokenizer' => 'standard',                     'filter' => array('standard', 'lowercase', 'lb_ngram')                 )             ),             'filter' => array(                 'lb_ngram' => array(                     "max_gram" => 10,                     "min_gram" => 1,                     "type" => "ngram"                 )             )         )             ), true     );     //create type     $elasticatype = $elasticaindex->gettype('profile');       // set mapping     $mapping->setproperties(array(         //'id' => array('type' => 'integer', 'include_in_all' => false),         'firstname' => array('type' => 'string', 'include_in_all' => true),         'lastname' => array('type' => 'string', 'include_in_all' => true),         'username' => array('type' => 'string', 'include_in_all' => true),         'bio' => array('type' => 'string', 'include_in_all' => true),         'thumbnail' => array('type' => 'string', 'include_in_all' => false),         'location' => array('type' => 'string', 'include_in_all' => true),     )); 

..... search, following

        $elasticaquerystring = new elastica\query\querystring();          //'and' or 'or' default : 'or'         $elasticaquerystring->setdefaultoperator('and');         $elasticaquerystring->setquery($term);          // create actual search object data.         $elasticaquery = new elastica\query();         $elasticaquery->setquery($elasticaquerystring); 

to add filter

            $elasticafilterlocation = new \elastica\filter\term();             //search 'location' = $region;             $elasticafilterlocation->setterm('location', $region);                        $elasticaquery->setfilter($elasticafilterlocation);             $elasticaresultset = $elasticaindex->search($elasticaquery);                             $elasticaresults = $elasticaresultset->getresults(); 

if comment out filter, expected results. missing? have analyzer or mapping?

i had same issue, fixed changing analyzers these fields in mappings. have rebuild indexes etc... don't try find solution change mapping or analyzer without rebuilding index, can't.

lc_analyzer' => array(    'type' => 'custom',    'tokenizer' => 'keyword',    'filter' => array('lowercase') ), 

for mapping:

'location' => array('type' => 'string', 'analyzer' => 'lc_analyzer'), 

then, query like

 $elasticafilterbool = new \elastica\filter\bool();                  $filter1 = new \elastica\filter\term();  $filter1->setterm('location', array(strtolower($region)));                  $elasticafilterbool->addmust($filter1);  $elasticaquery->setfilter($elasticafilterbool); 

i think location being tokenized on spaces , commas killing search. should solve you.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -