首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >访问脚本字段中的params['_source']时,Elasticsearch返回null_pointer_exception

访问脚本字段中的params['_source']时,Elasticsearch返回null_pointer_exception
EN

Stack Overflow用户
提问于 2018-10-24 18:56:37
回答 1查看 1.7K关注 0票数 0

当我在下面搜索文档时...

代码语言:javascript
运行
复制
GET /users/_search
{
  "query": {
    "function_score": {
        "query" : {
          "match_all": {}
        },
        "score_mode" : "sum",
        "boost_mode" : "sum",
        "script_score": {
          "script": {
            "lang": "painless",
            "source": "params['_source']"
          }
        }
      }
    }
  }

我得到了500个错误

代码语言:javascript
运行
复制
  {
"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’和参数‘_source’搜索,它就会移动。

问:我可以在"script_score“部分使用参数‘_source’吗?注: Elasticsearch版本为6.4.2。

EN

回答 1

Stack Overflow用户

发布于 2018-11-07 07:58:49

这就是我遇到类似问题的原因。根据elasticsearch的支持,预计elasticsearch 6.5中会修复此问题。

代码语言:javascript
运行
复制
    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": []
        }
    }

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52967227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档