2014-01-07 40 views
2

我是elasticsearch的新手,嘗試與elastica相處。我嘗試設置從特定類型建議的建議者。我試圖使用\ Elastica \ Search中的方法addType,但它不能工作。如何設置特定類型的Elastica建議?

$search = new \Elastica\Search($elasticaClient); 
$suggest = new \Elastica\Suggest\Term(); 
$suggest->addTerm('suggest', ['text' => $query, 'term' => ['field' => '_all']]); 
$search->addIndex($elasticaIndex); 
$search->addType($type); 
$search->addSuggest($suggest); 
$result = $search->search(); 

可能有人可以幫我解決它嗎? 感謝

回答

1

這裏是一個類型的搜索的例子:

$elasticaClient = new \Elastica\Client(array(
    'host' => 'localhost', 
    'port' => '9200', 
)); 
$type = $elasticaClient->getIndex('index_name')->getType('type_name'); 

$query = 'Text to be searched'; 

$suggest = new \Elastica\Suggest(); 
$term = new \Elastica\Suggest\Term('suggest', '_all'); 
$term->setText($query); 
$suggest->addSuggestion($term); 

$result = $type->search($suggest); 

欲瞭解更多信息,你可以看看http://elastica.io/migration/0.90.7/suggest.html

相關問題