一、bug描述
DSL语句:
{
"from": 0,
"size": 5,
"query": {
"bool": {
"must": [
{
"term": {
"is_deleted": {
"value": "false",
"boost": 1.0
}
}
},
{
"function_score": {
"query": {
"bool": {
"should": [
{
"nested": {
"query": {
"bool": {
"should": [
{
"term": {
"member.name.pinyin": {
"value": "鲁霞",
"boost": 0.5
}
}
}
],
"adjust_pure_negative": true,
"boost": 10.0
}
},
"path": "member",
"ignore_unmapped": false,
"score_mode": "avg",
"boost": 5.0,
"inner_hits": {
"ignore_unmapped": false,
"from": 0,
"size": 3,
"version": false,
"explain": false,
"track_scores": false,
"highlight": {
"fields": {
"*": {}
}
}
}
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"boost": 3.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"track_scores": true,
"highlight": {
"fields": {
"*": {}
}
}
}
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 6,
"successful": 5,
"skipped": 0,
"failed": 1,
"failures": [
{
"shard": 1,
"index": "jingdata_project",
"node": "sM3Z-9snQuexvj5V5EfswQ",
"reason": {
"type": "illegal_argument_exception",
"reason": "offset out of bounds"
}
}
]
},
"hits": {
"total": 2,
"max_score": 1279.1053,
"hits": [
{省略}
]
}
}
查询结果中报错(offset out of bounds),显示一个分片查询失败,并且结果中total为2,实际只返回1条数据。
二、bug原因
"highlight": {
"fields": {
"*": {}
}
}
查询DSL高亮配置中,不能直接写通配符*,需要指定具体的字段名称
三、解决办法
需要把对应DSL改成如下语句
"highlight": {
"fields": {
"member.name": {}
}
}
四、参考资料
1、https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html