";
printf("Total docs: %d\n", $response['hits']['total']['value']);
echo "
";
printf("Max score : %.4f\n", $response['hits']['max_score']);
echo "
";
printf("Took : %d ms\n", $response['took']);
echo "";
}
function displayResult($response){
$hits=$response['hits']['total']['value'];
$result = null;
$i = 0;
while ($i < $hits) {
$result[$i] = $response['hits']['hits'][$i]['_source'];
$i++;
}
$row = 0;
foreach ($result as $key => $value) {
//while ($row < 15) {
echo $value['id'] . " : ";
echo $value['firstname'] . " : ";
echo $value['lastname'] . " : ";
echo $value['email'] . "
";
//}
//$row++;
}
echo "
";
}
//
if ($index_status == 200) {
// search one item
$params = [
'index' => $es_index,
'from' => 0, // <--- Start at #1
'size' => 10,
'body' => [
'query' => [
'match' => [
'firstname' => 'chantal'
]
]
]
];
$response = $client->search($params);
echo "Result of the research 'match (chantal)'";
displayInfoSearch($response);
displayResult($response);
// Search wildcard
$params = [
'index' => $es_index,
'body' => [
'query' => [
'wildcard' => ["firstname" => "yv*"]
]
]
];
$response = $client->search($params);
echo "Result of the research 'wildcard (yv*)'";
displayInfoSearch($response);
displayResult($response);
// Search all item
$params = [
'index' => $es_index,
'body' => '{
"from": 0,
"size": 100, //dispay 100 result (default is 10)
"query": {
"match_all": {}
}
}',
];
$response = $client->search($params);
echo "Result of the research 'match_all'";
displayInfoSearch($response);
displayResult($response);
}
else {
echo "Problem with index ".$es_index." (".$index_status.")";
}
?>