MikeT1234
(Mike)
September 25, 2023, 3:13pm
1
Could somebody point me to the right direction?
I'm trying to search items and categorize / score them based on several criteria.
function_score
seems to do all the right things except I it just returns total sum of scores instead of scores for each functions.
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"functions": [
{
"filter": {
"match": {
"industry.group.code": "A"
}
},
"weight": 70
},
{
"filter": {
"match": {
"name": "Apple"
}
},
"weight": 30
}
],
"score_mode": "sum",
"boost_mode": "sum",
"min_score": 42
}
}
}
I've been trying to add missing scores fields by using script_score
but failed so far.
{
"filter": {
"match": {
"industry.group.code": "A"
}
},
"script_score": {
"script": {
"lang": "painless",
"source": "ctx._source.score_industry == _score // <-- THIS DOESNT WORK; return _score;"
}
},
"weight": 70
}
I found this topic but it seemed to be quite old
opened 10:19PM - 18 Aug 16 UTC
closed 07:09PM - 13 Mar 18 UTC
discuss
:Core/Infra/Scripting
v6.0.3
<!--
GitHub is reserved for bug reports and feature requests. The best place
to … ask a general question is at the Elastic Discourse forums at
https://discuss.elastic.co. If you are in fact posting a bug report or
a feature request, please include one and only one of the below blocks
in your new issue. Note that whether you're filing a bug report or a
feature request, ensure that your submission is for an
[OS that we support](https://www.elastic.co/support/matrix#show_os).
Bug reports on an OS that we do not support or feature requests
specific to an OS that we do not support will be closed.
-->
<!--
If you are filing a bug report, please remove the below feature
request block and provide responses for all of the below items.
-->
**Elasticsearch version**: master
**Plugins installed**: none
**JVM version**: 1.8.0_60
**OS version**: OSX El Capitan
**Description of the problem including expected versus actual behavior**:
According to [the docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-script-fields.html) `script_fields` can access the document _source via a `_source` keyword. When attempting this with a Painless script, I get a `Variable [_source] is not defined.` error.
**Steps to reproduce**:
1. Execute a query with a painless script_field that attempts to access _source, something like this:
```
"script_fields": {
"scriptip": {
"script": {
"inline": "return _source.ip;",
"lang": "painless"
}
}
}
```
**Provide logs (if relevant)**:
```
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"return _source.ip;",
" ^---- HERE"
],
"script": "return _source.ip;",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query_fetch",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "logstash-0",
"node": "00s71MPnSRenvz6mflLQeQ",
"reason": {
"type": "script_exception",
"reason": "compile error",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Variable [_source] is not defined."
},
"script_stack": [
"return _source.ip;",
" ^---- HERE"
],
"script": "return _source.ip;",
"lang": "painless"
}
}
],
"caused_by": {
"type": "script_exception",
"reason": "compile error",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Variable [_source] is not defined."
},
"script_stack": [
"return _source.ip;",
" ^---- HERE"
],
"script": "return _source.ip;",
"lang": "painless"
}
},
"status": 500
}
```
**Describe the feature**:
So I'm wondering if it's possible to add new fields under script_score or are there any alternative way to do this?
MikeT1234
(Mike)
September 27, 2023, 6:46am
2
I would appreciate your comments about this
Can anyone push me to the right direction?
system
(system)
Closed
November 6, 2023, 1:36pm
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.