From 1dd26888f6bc1f34aca97a5400dbc1a99f42163c Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 11 Sep 2014 12:52:58 +0200 Subject: [PATCH] [DOCS] Additional documentation for _score accessing Closes #7043 --- docs/reference/modules/scripting.asciidoc | 10 ++++++++-- .../aggregations/metrics/tophits-aggregation.asciidoc | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/reference/modules/scripting.asciidoc b/docs/reference/modules/scripting.asciidoc index 7d9860ba845..bf42a8da361 100644 --- a/docs/reference/modules/scripting.asciidoc +++ b/docs/reference/modules/scripting.asciidoc @@ -305,8 +305,7 @@ There are a few limitations relative to other script languages: === Score In all scripts that can be used in aggregations, the current -document's score is accessible in `doc.score`. When using a `script_score`, -the current score is available in `_score`. +document's score is accessible in `_score`. [float] === Computing scores based on terms in scripts @@ -410,6 +409,13 @@ are much slower to access compared with document fields, as they are not loaded into memory. They can be simply accessed using `_fields['my_field_name'].value` or `_fields['my_field_name'].values`. +[float] +=== Accessing the score of a document within a script + +When using scripting for calculating the score of a document (for instance, with +the `function_score` query), you can access the score using the `_score` +variable inside of a Groovy script. + [float] === Source Field diff --git a/docs/reference/search/aggregations/metrics/tophits-aggregation.asciidoc b/docs/reference/search/aggregations/metrics/tophits-aggregation.asciidoc index 95a1b1a0c29..d4978619521 100644 --- a/docs/reference/search/aggregations/metrics/tophits-aggregation.asciidoc +++ b/docs/reference/search/aggregations/metrics/tophits-aggregation.asciidoc @@ -184,7 +184,7 @@ relevancy order of the most relevant document in a bucket. }, "top_hit" : { "max": { - "script": "_doc.score" + "script": "_score" } } }