当我在查询中使用random_score时,我发现获取查询结果需要大约150毫秒(如果不使用random_score,则需要大约250毫秒才能得到结果)。
原始查询
{
"size": 10,
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"query_string": {
"fields": [
"sound_title",
"album_title"
],
"query": "0"
}
}
]
}
},
"functions": [
{
"filter": {
"bool": {
"must": [
{
"term": {
"sound_chapters": 1
}
}
]
}
},
"weight": 1.2
},
{
"field_value_factor": {
"field": "album_playcount",
"modifier": "log",
"missing": "100"
}
}
],
"score_mode": "sum"
}
}
}
使用random_score查询
{
"size": 10,
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"query_string": {
"fields": [
"sound_title",
"album_title"
],
"query": "0"
}
}
]
}
},
"functions": [
{
"filter": {
"bool": {
"must": [
{
"term": {
"sound_chapters": 1
}
}
]
}
},
"weight": 1.2
},
{
"field_value_factor": {
"field": "album_playcount",
"modifier": "log",
"missing": "100"
}
},
{
"random_score": {
"seed": "123"
}
}
],
"score_mode": "sum"
}
}
}
有没有办法优化查询以提高性能?