当前位置: 首页 > elasticsearch, 搜索 > 正文

elasticsearch customScoreQuery NullPointerException

1 星2 星3 星4 星5 星 (1 次投票, 评分: 5.00, 总分: 5)
Loading ... Loading ...
baidu_share

接着上一篇文章elasticsearch customScoreQuery 实例
当时操作出现了空指针错误。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[2013-06-08 16:44:00,730][DEBUG][action.search.type       ] [Golem] [test][1], node[h9UqCv4wTECtb_VLWnkxcQ], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@175edcf]
org.elasticsearch.search.query.QueryPhaseExecutionException: [test][1]: query[filtered(custom score (title:北,function=script[long x=Long.parseLong(doc['updatetime'].value);x=x/86400l;long nows=yy/86400l;int nowDay=(int)nows;int day=(int)x;if (day < nowDay) {} else if (day > nowDay) {} else{}], params [{_source=org.elasticsearch.search.lookup.SourceLookup@1cfefc3, nows=15864, _fields=org.elasticsearch.search.lookup.FieldsLookup@86100a, _doc=org.elasticsearch.search.lookup.DocLookup@1871341, doc=org.elasticsearch.search.lookup.DocLookup@1871341, day=15910, _score=0.13424811, nowDay=15864, yy=1370681040, x=15910.719386574074}]))->cache(_type:xq)],from[0],size[60]: Query Failed [Failed to execute main query]
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:138)
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:239)
	at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:141)
	at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)
	at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:206)
	at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:193)
	at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:179)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
	at org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.runAsFloat(MvelScriptEngineService.java:197)
	at org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction.score(CustomScoreQueryParser.java:135)
	at org.elasticsearch.common.lucene.search.function.FunctionScoreQuery$CustomBoostFactorScorer.score(FunctionScoreQuery.java:155)
	at org.apache.lucene.search.TopScoreDocCollector$OutOfOrderTopScoreDocCollector.collect(TopScoreDocCollector.java:140)
	at org.apache.lucene.search.Scorer.score(Scorer.java:65)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:612)
	at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:161)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:482)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:438)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)
	at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:134)
	... 9 more

代码为:

1
2
3
4
new CustomScoreQueryBuilder(getQueryBuilder(query)).script(
				"long x=Long.parseLong(doc['updatetime'].value);" +
		        "x=x/86400l;"	
				).param("yy", System.currentTimeMillis()/1000l/86400l)

从上面代码看,script没有问题,最后查到原因,CustomScoreQueryBuilder 必须要对_score 赋值,不然回报空指针错误。

本文固定链接: http://www.chepoo.com/elasticsearch-custom-score-query-null-pointer-exception.html | IT技术精华网

elasticsearch customScoreQuery NullPointerException:等您坐沙发呢!

发表评论