You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: _query-dsl/compound/function-score.md
+194-1
Original file line number
Diff line number
Diff line change
@@ -826,4 +826,197 @@ The results contain the three matching blog posts:
826
826
}
827
827
}
828
828
```
829
-
</details>
829
+
</details>
830
+
831
+
## Named functions
832
+
833
+
When defining a function, you can specify its name using the `_name` parameter at the top level. This name is useful for debugging and understanding the scoring process. Once specified, the function name is included in the score calculation explanation whenever possible (this applies to functions, filters, and queries). You can identify the function by its `_name` in the response.
834
+
835
+
### Example
836
+
837
+
The following request sets `explain` to `true` for debugging purposes in order to obtain a scoring explanation in the response. Each function contains a `_name` parameter so that you can identify the function unambiguously:
838
+
839
+
```json
840
+
GET blogs/_search
841
+
{
842
+
"explain": true,
843
+
"size": 1,
844
+
"query": {
845
+
"function_score": {
846
+
"functions": [
847
+
{
848
+
"_name": "likes_function",
849
+
"script_score": {
850
+
"script": {
851
+
"lang": "painless",
852
+
"source": "return doc['likes'].value * 2;"
853
+
}
854
+
},
855
+
"weight": 0.6
856
+
},
857
+
{
858
+
"_name": "views_function",
859
+
"field_value_factor": {
860
+
"field": "views",
861
+
"factor": 1.5,
862
+
"modifier": "log1p",
863
+
"missing": 1
864
+
},
865
+
"weight": 0.3
866
+
},
867
+
{
868
+
"_name": "comments_function",
869
+
"gauss": {
870
+
"comments": {
871
+
"origin": 1000,
872
+
"scale": 800
873
+
}
874
+
},
875
+
"weight": 0.1
876
+
}
877
+
]
878
+
}
879
+
}
880
+
}
881
+
```
882
+
{% include copy-curl.html %}
883
+
884
+
The response explains the scoring process. For each function, the explanation contains the function `_name` in its `description`:
0 commit comments