-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquery_score_search.php
50 lines (46 loc) · 1.58 KB
/
query_score_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
41
42
43
44
45
46
47
48
49
50
<?php
require 'vendor/autoload.php';
$client = \Elasticsearch\ClientBuilder::fromConfig([
'hosts' => ['localhost:9200'],
'retries' => 2,
]);
$resp = $client->search(
[
'index' => 'article',
'type' => 'doc',
'body' => [
// 需要相关性的, 写在query context中
'query' => [
'bool' => [
'must' => [
[
// 中文分词或者拼音分词匹配皆可, 综合打分
'multi_match' => [
'query' => '数据线',
'fields' => [
'article_title', 'article_title.pinyin', 'article_content'
],
'type' => 'most_fields',
]
],
],
// 是/否的判定, 写在filter context中,比如term过滤
'filter' => [
[
'term' => ['article_is_anonymous' => false]
],
[
'nested' => [
'path' => 'article_category',
'query' => [
'term' => ['article_category.cate_name' => '手机'],
],
],
]
]
],
]
]
]
);
print_r($resp);