兼容统计字段为空
This commit is contained in:
parent
9b733a1923
commit
48b4d89510
@ -301,7 +301,6 @@ func (svc *BookService) UpdateBookFieldsByISBN(request *request.BookUpdateReques
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
payload, _ := json.Marshal(body)
|
payload, _ := json.Marshal(body)
|
||||||
|
|
||||||
res, err := svc.esClient.Client.UpdateByQuery(
|
res, err := svc.esClient.Client.UpdateByQuery(
|
||||||
[]string{es.ESIndex},
|
[]string{es.ESIndex},
|
||||||
svc.esClient.Client.UpdateByQuery.WithBody(bytes.NewReader(payload)),
|
svc.esClient.Client.UpdateByQuery.WithBody(bytes.NewReader(payload)),
|
||||||
@ -1233,15 +1232,50 @@ func (svc *BookService) buildNumericRangeConditions(builder *ESQueryBuilder, req
|
|||||||
}
|
}
|
||||||
esField := esFields[fieldName]
|
esField := esFields[fieldName]
|
||||||
parts := strings.Split(value, ",")
|
parts := strings.Split(value, ",")
|
||||||
|
fmt.Println("ppp", fieldName, parts)
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
minVal, _ := strconv.Atoi(parts[0])
|
minVal, _ := strconv.Atoi(parts[0])
|
||||||
maxVal, _ := strconv.Atoi(parts[1])
|
maxVal, _ := strconv.Atoi(parts[1])
|
||||||
builder.AddQuery(&QueryCondition{
|
// 如果查询范围包含 0(0-999999),需要同时匹配 null 值
|
||||||
Field: esField,
|
if minVal == 0 {
|
||||||
Type: "range",
|
// 使用 bool should 查询:匹配范围内值 OR 字段为 null/不存在
|
||||||
GTE: minVal,
|
rangeQuery := map[string]interface{}{
|
||||||
LTE: maxVal,
|
"range": map[string]interface{}{
|
||||||
})
|
esField: map[string]interface{}{
|
||||||
|
"gte": minVal,
|
||||||
|
"lte": maxVal,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
nullQuery := map[string]interface{}{
|
||||||
|
"bool": map[string]interface{}{
|
||||||
|
"must_not": []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"exists": map[string]interface{}{
|
||||||
|
"field": esField,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.AddBoolQuery("should", []map[string]interface{}{rangeQuery, nullQuery})
|
||||||
|
} else {
|
||||||
|
// 普通范围查询,不包含 null 值
|
||||||
|
builder.AddQuery(&QueryCondition{
|
||||||
|
Field: esField,
|
||||||
|
Type: "range",
|
||||||
|
GTE: minVal,
|
||||||
|
LTE: maxVal,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
//builder.AddQuery(&QueryCondition{
|
||||||
|
// Field: esField,
|
||||||
|
// Type: "range",
|
||||||
|
// GTE: minVal,
|
||||||
|
// LTE: maxVal,
|
||||||
|
//})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user