user3658423
user3658423

Reputation: 1944

elasticsearch sort vs score - efficiency?

I have an elasticsearch index that contains few million records. (log records based on timestamp)

I need to display the newest records first (ie. records in descending order of timestamp)

Is sort desc on timestamp more efficient (speed, memory efficiency) than function score function using timestamp?

"script_score" : {
    "script" : "doc['timestamp'].value"
}

Upvotes: 0

Views: 822

Answers (1)

imotov
imotov

Reputation: 30163

Using sort desc on timestamp will be more efficient in terms of speed. In both cases all values for the timestamp will be loaded into memory to build in-memory structure called field-data, so the memory footprint will be approximately the same. However, in case of direct sort on the field, you will avoid going through the scripting engine code for each record.

It will be also more precise since score is represented as float and timestamps will remain long when you sort by the field.

Upvotes: 2

Related Questions