Py学习  »  Elasticsearch

ElasticSearch在访问脚本字段中的参数[“源”]时返回空的_指针_异常

wgkoro • 4 年前 • 740 次点击  

当我搜索下面的文档时…

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”和参数“_source”]搜索,它会移动。

问题: 我可以在“脚本分数”部分使用参数[“源”]? 注:ElasticSearch版本为6.4.2。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38324
 
740 次点击  
文章 [ 1 ]  |  最新文章 4 年前
kongshukong
Reply   •   1 楼
kongshukong    5 年前

这就是我遇到类似问题的原因。根据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": []
        }
    }