forked from ken88/php-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
40 lines (37 loc) · 876 Bytes
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
# 搜索
require 'vendor/autoload.php';
$host = [
'http://localhost:9200' //IP+端口
];
/**
* number_of_replicas 是数据备份数,如果只有一台机器,设置为0
* number_of_shards 是数据分片数,默认为5,有时候设置为3
*/
$client = Elasticsearch\ClientBuilder::create()->setHosts($host)->build();
$params = [
'index' => 'goods',
'body' => [
'query' => [
'match' => [
'original_img' => 'images'
]
],
'highlight' => [
"pre_tags"=> ["<span style='color: red'>"],
"post_tags"=> ["</span>"],
'fields' => [
'original_img' => new \stdClass()
]
]
]
];
$response = $client->search($params);
dd($response);
function dd($data) {
echo "<pre>";
print_r($data);
echo "</pre>";
exit;
}
?>