Reputation: 23
When i use random_score in the query, i found that it costs about 150 more milliseconds to get the query result(if not use random_score, it takes about 250 milliseconds to get the result).
original query
{
"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"
}
}
}
query with 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"
}
}
}
are there any way to optimize the query to enhance better performance?
Upvotes: 2
Views: 1516
Reputation: 2270
If you are adding any more function to any ElasticSearch
query, ES
would take some processing time to include the score of that function into main score, thereby increasing overall time.
You can read more on Random scoring in elasticsearch here.
Most common way to increase query performance is to use filters
instead of query
as filters are cached. But it should be done if you have enough memory in your server.
You can get more ideas from the blog here.
Upvotes: 3