vendredi 12 juin 2015

How can I use Elasticsearch's function score to make "randomize" search results in PHP?

My existing search looks like this:

$searchParams['body']['query']['filtered']['query']["match_all"] = array("boost" => 1);

How do I add function_score to this search? Here's what I have right now

$randomScore = new \stdClass();
// will be date or userid in the future
$randomScore->seed = 5; 
$functionScore = array(
            array("random_score" => $randomScore)
        );
$searchParams['body']['query']['function_score']['functions'] = $functionScore;
$queryResponse = $client->search($searchParams);

Seems really close to being correct.




Aucun commentaire:

Enregistrer un commentaire