当我使用以下内容搜索文档时...
GET /users/_search
{
"query": {
"function_score": {
"query" : {
"match_all": {}
},
"score_mode" : "sum",
"boost_mode" : "sum",
"script_score": {
"script": {
"lang": "painless",
"source": "params['_source']"
}
}
}
}
}
我遇到500错误
{
"shard": 0,
"index": "users",
"node": "xxxxxxxxxxxxxxxxxxx",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"params._source",
" ^---- HERE"
],
"script": "params._source",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
如果我使用'script_fields'而不是'script_score'和params ['_ source']搜索,它将移动。
问题: 我可以在“ script_score”部分中使用params ['_ source']吗? 注意:Elasticsearch版本为6.4.2。
答案 0 :(得分:0)
这就是我遇到类似问题的方式。根据elasticsearch的支持,预计它将在Elasticsearch 6.5中修复。
GET http://localhost:9200/
{
"name": "hBCIuC6",
"cluster_name": "elasticsearch",
"cluster_uuid": "HxBX1gFSSAOBcDuysqa16Q",
"version": {
"number": "6.4.2",
},
"tagline": "You Know, for Search"
}
DELETE http://localhost:9200/myindex
PUT http://localhost:9200/myindex/_doc/1
{
"my_score":0.99,
"item_id":1
}
{
"_index": "myindex",
"_type": "_doc",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
POST http://localhost:9200/myindex/_search
{
"query":{
"match_all":{
}
},
"rescore" : [ {
"window_size" : 10,
"query" : {
"score_mode": "multiply",
"rescore_query" : {
"function_score" : {
"script_score": {
"script": {
"source": "params._source.my_score"
}
}
}
}
}
} ]
}
{
"took": 54,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 1,
"failures": [
{
"shard": 3,
"index": "myindex",
"node": "hBCIuC6qQoKLQttBxHs20Q",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"params._source.my_score",
" ^---- HERE"
],
"script": "params._source.demotion_seller",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}