访问ElasticSearch无痛脚本化指标聚合参数时出现NullPointerExceptions

时间:2018-11-16 11:00:11

标签: java elasticsearch nullpointerexception elasticsearch-aggregation elasticsearch-painless

在脚本化聚合的map_script中访问doc时,我不断收到空指针异常。

对于

{
    "init_script":{
        "source":"params._agg['transactions'] = [];"
    },
    "map_script":{
        "source":"Debug.explain(params)"        <----------------
    },
    ...
}

我明白了

{
    ...,
    "painless_class":"java.util.HashMap",
    "to_string":"{doc=org.elasticsearch.search.lookup.LeafDocLookup@133b9d24, _source=org.elasticsearch.search.lookup.SourceLookup@7b812d13, _doc=org.elasticsearch.search.lookup.LeafDocLookup@133b9d24, _fields=org.elasticsearch.search.lookup.LeafFieldsLookup@6149f5f3, _agg={transactions=[]}}",
    "java_class":"java.util.HashMap",
    ...
}

在这里,Debug.explain(params._agg)可以访问而不会出现问题,Debug.explain(params.containsKey('doc'))也会返回

{
    ...,
    "painless_class":"java.lang.Boolean",
    "to_string":"true",
    "java_class":"java.lang.Boolean",
    ...
}

但是,如果我访问

  • params.doc
  • params['_doc']
  • doc
  • _doc
  • 或这些的任何变体

我不断得到

{
    ...,
    "caused_by":{
        "type":"null_pointer_exception",
        "reason":null,
        "caused_by":{
            "type":"null_pointer_exception",
            "reason":null
        }
    },
    ...
}

发生了什么事?为什么我看到LeafDocLookup实例无法访问并且显示为非字符串/ toString()-ed?


Kibana堆栈跟踪:

{
    "error":{
        "root_cause":[
            {
                "type":"null_pointer_exception",
                "reason":null
            }
        ],
        "type":"search_phase_execution_exception",
        "reason":"all shards failed",
        "phase":"query",
        "grouped":true,
        "failed_shards":[
            {
                "shard":0,
                "index":"abcdefgh",
                "node":"C2dBtzqBQOOiH5G5IGQPkQ",
                "reason":{
                    "type":"null_pointer_exception",
                    "reason":null
                }
            }
        ],
        "caused_by":{
            "type":"null_pointer_exception",
            "reason":null,
            "caused_by":{
                "type":"null_pointer_exception",
                "reason":null
            }
        }
    },
    "status":500
}

ES堆栈跟踪

org.elasticsearch.action.search.SearchPhaseExecutionException: all shards failed
    at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:288) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:128) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:249) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.InitialSearchPhase.onShardFailure(InitialSearchPhase.java:101) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.InitialSearchPhase.access$100(InitialSearchPhase.java:48) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.InitialSearchPhase$2.lambda$onFailure$1(InitialSearchPhase.java:222) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.InitialSearchPhase.maybeFork(InitialSearchPhase.java:176) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.InitialSearchPhase.access$000(InitialSearchPhase.java:48) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.InitialSearchPhase$2.onFailure(InitialSearchPhase.java:222) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.SearchExecutionStatsCollector.onFailure(SearchExecutionStatsCollector.java:73) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:51) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:527) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1103) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1196) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1180) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:66) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.SearchTransportService$6$1.onFailure(SearchTransportService.java:385) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.SearchService$2.onFailure(SearchService.java:341) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:335) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:329) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.SearchService$3.doRun(SearchService.java:1019) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:725) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41) [elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.3.1.jar:6.3.1]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_121]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
Caused by: org.elasticsearch.ElasticsearchException$1
    at org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:658) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:126) ~[elasticsearch-6.3.1.jar:6.3.1]
    ... 26 more
Caused by: java.lang.NullPointerException
    at org.elasticsearch.painless.Definition.getTypeInternal(Definition.java:1364) ~[?:?]
    at org.elasticsearch.painless.Definition.getType(Definition.java:447) ~[?:?]
    at org.elasticsearch.painless.Definition.ClassToType(Definition.java:615) ~[?:?]
    at org.elasticsearch.painless.PainlessExplainError.getHeaders(PainlessExplainError.java:57) ~[?:?]
    at org.elasticsearch.painless.PainlessScript$Script.execute(Debug.explain(params['doc']):21) ~[?:?]
    at org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:105) ~[?:?]
    at org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregator$1.collect(ScriptedMetricAggregator.java:71) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.aggregations.LeafBucketCollector$2.collect(LeafBucketCollector.java:67) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.aggregations.LeafBucketCollector.collect(LeafBucketCollector.java:82) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.apache.lucene.search.MultiCollector$MultiLeafCollector.collect(MultiCollector.java:174) ~[lucene-core-7.3.1.jar:7.3.1 ae0705edb59eaa567fe13ed3a222fdadc7153680 - caomanhdat - 2018-05-09 09:27:24]
    at org.apache.lucene.search.FilterLeafCollector.collect(FilterLeafCollector.java:43) ~[lucene-core-7.3.1.jar:7.3.1 ae0705edb59eaa567fe13ed3a222fdadc7153680 - caomanhdat - 2018-05-09 09:27:24]
    at org.apache.lucene.search.Weight$DefaultBulkScorer.scoreAll(Weight.java:233) ~[lucene-core-7.3.1.jar:7.3.1 ae0705edb59eaa567fe13ed3a222fdadc7153680 - caomanhdat - 2018-05-09 09:27:24]
    at org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:184) ~[lucene-core-7.3.1.jar:7.3.1 ae0705edb59eaa567fe13ed3a222fdadc7153680 - caomanhdat - 2018-05-09 09:27:24]
    at org.apache.lucene.search.ConstantScoreQuery$ConstantBulkScorer.score(ConstantScoreQuery.java:84) ~[lucene-core-7.3.1.jar:7.3.1 ae0705edb59eaa567fe13ed3a222fdadc7153680 - caomanhdat - 2018-05-09 09:27:24]
    at org.apache.lucene.search.BulkScorer.score(BulkScorer.java:39) ~[lucene-core-7.3.1.jar:7.3.1 ae0705edb59eaa567fe13ed3a222fdadc7153680 - caomanhdat - 2018-05-09 09:27:24]
    at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:660) ~[lucene-core-7.3.1.jar:7.3.1 ae0705edb59eaa567fe13ed3a222fdadc7153680 - caomanhdat - 2018-05-09 09:27:24]
    at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:191) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:462) ~[lucene-core-7.3.1.jar:7.3.1 ae0705edb59eaa567fe13ed3a222fdadc7153680 - caomanhdat - 2018-05-09 09:27:24]
    at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:266) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:107) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:324) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:357) ~[elasticsearch-6.3.1.jar:6.3.1]
    at org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:333) ~[elasticsearch-6.3.1.jar:6.3.1]

0 个答案:

没有答案