elasticsearch bool 的坑

来源:互联网 发布:已知数据求标准误 编辑:程序博客网 时间:2024/06/05 06:22

{
“query”: {
“bool”: {
“must_not”: [
{
“term”: {
“item_type”: 4
}
},
{
“term”: {
“can_see”: true
}
}
],
“should”: [
{
“regexp”: {
“item_no”: “.?2602.?”
}
},
{
“regexp”: {
“description”: “.?2602.?”
}
},
{
“regexp”: {
“series_name”: “.?2602.?”
}
},
{
“regexp”: {
“name”: “.?2602.?”
}
}
]
}
}
}
结果是must_not and should
{
“query”: {
“bool”: {
“must”: [
{
“term”: {
“item_type”: 4
}
},
{
“term”: {
“can_see”: true
}
}
],
“should”: [
{
“regexp”: {
“item_no”: “.?2602.?”
}
},
{
“regexp”: {
“description”: “.?2602.?”
}
},
{
“regexp”: {
“series_name”: “.?2602.?”
}
},
{
“regexp”: {
“name”: “.?2602.?”
}
}
]
}
}
}
结果是must or should
原因是:bool查询也是采用more_matches_is_better的机制,因此满足must和should子句的文档将会合并起来计算分值。