2016-05-10 65 views
0

我使用的是Laravel 5.1mustafaaloko/elasticquent5包(found here)。Elasticsearch不返回部分结果

但是当试图返回结果时,我只能在搜索确切的单词时得到结果。如果我尝试搜索部分单词,它将不会返回任何内容。

我使用Profile::addAllToIndex();dd(Profile::search(Input::get('search_term')));

我的配置是这样的:

<?php 

return array(

    /* 
    |-------------------------------------------------------------------------- 
    | Custom Elasticsearch Client Configuration 
    |-------------------------------------------------------------------------- 
    | 
    | This array will be passed to the Elasticsearch client. 
    | See configuration options here: 
    | 
    | http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_configuration.html 
    */ 

    'config' => [ 
     'hosts'  => ['ahp.dev:9200'], 
     'logging' => true, 
     'logPath' => storage_path() . '/logs/elasticsearch.log', 
     'logLevel' => Monolog\Logger::WARNING, 
    ], 

    /* 
    |-------------------------------------------------------------------------- 
    | Default Index Name 
    |-------------------------------------------------------------------------- 
    | 
    | This is the index name that Elastiquent will use for all 
    | Elastiquent models. 
    */ 

    'default_index' => 'default', 

); 

回答

1

你应该尝试使用searchByQuery,而不是search和使用query_string查询

Profile::searchByQuery(array('query_string' => array('query' => Input::get('search_term')))); 
+0

我不得不在Input :: get('search_term')'之前和之后加入''*'来进行适应性调整,然后它就起作用了!谢谢! – Haring10

+0

哦,是的,忘记了。伟大的工作!一旦等待期结束, – Val

+0

将接受正确答案 – Haring10