我需要为 flex 搜索数据库设置一个简单的条件,如果结果为null,它将显示搜索结果不存在。
$result = $client->search($params);
但是在 flex 搜索中,即使结果为null,它也会返回-
Array (
[took] => 1
[timed_out] =>
[_shards] => Array (
[total] => 2
[successful] => 2
[failed] => 0
)
[hits] => Array (
[total] => 0
[max_score] =>
[hits] => Array ( )
)
)
因此,当我设置条件以检查结果是否为null时,由于前一行,我猜它将永远不会执行。
if ($result != null ){
echo ($result);
} else {
echo "Your search doesnot exists";
}
因此,当结果返回空值时,如何简单地设置 flex 搜索条件。
最佳答案
尝试:
if ($result['hits']['total'] > 0 ){
echo ($result);
} else {
echo "Your search doesnot exists";
}
关于php - elasticsearch搜索结果为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32047892/