title或者content包含xx(should)
type必须是1(must)
enabled必须是1(must_not)
GET _search
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"title": "疫情期间"
}
},
{
"match_phrase": {
"content": "疫情期间"
}
}
],
"must_not": [
{
"match": {
"enabled": 0
}
}
]
}
},
"highlight": {
"pre_tags": [
"<font color='red'>"
],
"post_tags": [
"</font>"
],
"fields": {
"title": {},
"content": {}
}
}
}
GET _search
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"title": "疫情期间"
}
},
{
"match_phrase": {
"content": "疫情期间"
}
}
],
"must": [
{"match": {
"type": "1"
}}
],
"must_not": [
{
"match": {
"enabled": 0
}
}
]
}
},
"highlight": {
"pre_tags": [
"<font color='red'>"
],
"post_tags": [
"</font>"
],
"fields": {
"title": {},
"content": {}
}
}
}
使用多个must嵌套查询 将should组成的bool查询包含在其中一个must查询中

GET _search
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match_phrase": {
"title": "疫情期间"
}
},
{
"match_phrase": {
"content": "疫情期间"
}
}
]
}
},
{
"match": {
"type": "1"
}
}
],
"must_not": [
{
"match": {
"enabled": 0
}
}
]
}
},
"highlight": {
"pre_tags": [
"<font color='red'>"
],
"post_tags": [
"</font>"
],
"fields": {
"title": {},
"content": {}
}
}
}
//PHP代码实现,$this->must是完整的must条件
$keys = ['name', 'scope', 'oper_name', 'address', 'employees', 'partners', 'products'];
$should = [];
foreach ($keys as $key) {
$should[] = ['match_phrase' => [$key => $this->$attribute]];
}
unset($key);
if(!empty($should)){
$this->must[] = [
'bool' => [
'should' => $should,
],
];
}无论从事什么行业,只要做好两件事就够了,一个是你的专业、一个是你的人品,专业决定了你的存在,人品决定了你的人脉,剩下的就是坚持,用善良專業和真诚赢取更多的信任。