我对弹性搜索很新,并尝试与弹性相处。我尝试设置建议从特定类型建议。我曾尝试使用\ Elastica \ Search中的方法addType,但它不起作用。
$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();
有人可以帮我解决一下吗?
感谢
答案 0 :(得分: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);