我要做的就是从fuzzy_like_this查询中获取分数以进行进一步处理。它不起作用,但正常的查询有效。
这很有效,
POST /merchantindex/_search
{
"query": {
"function_score" : {
"query" :{
"query_string": { "query": "tes"}
},
"functions": [
{
"script_score": {
"script": "return _score/log(1.1 + sqrt(pow(_source.userLoc.coordinates[0] - _source.loc.coordinates[0],2)+pow(_source.userLoc.coordinates[1] - _source.loc.coordinates[1],2)));"
}
}
]
}
}
}
但这没有用,
POST /merchantindex/_search
{
"query": {
"function_score" : {
"query" :{
"fuzzy_like_this" : {
"fields" : ["title", "desc", "loc.locNm", "category", "subCategoryList.subCategory"],
"like_text" : "tes",
"max_query_terms" : 12
}
},
"functions": [
{
"script_score": {
"script": "return _score/log(1.1 + sqrt(pow(_source.userLoc.coordinates[0] - _source.loc.coordinates[0],2)+pow(_source.userLoc.coordinates[1] - _source.loc.coordinates[1],2)));"
}
}
]
}
}
}
我得到的错误是
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[H94j5eYQRXantctqOKMduw][merchantindex][0]: QueryPhaseExecutionException[[merchantindex][0]: query[function score (null,function=script[return _score/log(1.1 + sqrt(pow(_source.userLoc.coordinates[0] - _source.loc.coordinates[0],2)+pow(_source.userLoc.coordinates[1] - _source.loc.coordinates[1],2)));], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[NullPointerException[null]]; }{[H94j5eYQRXantctqOKMduw][merchantindex][1]: QueryPhaseExecutionException[[merchantindex][1]: query[function score (null,function=script[return _score/log(1.1 + sqrt(pow(_source.userLoc.coordinates[0] - _source.loc.coordinates[0],2)+pow(_source.userLoc.coordinates[1] - _source.loc.coordinates[1],2)));], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[NullPointerException[null]]; }{[H94j5eYQRXantctqOKMduw][merchantindex][2]: QueryPhaseExecutionException[[merchantindex][2]: query[function score (null,function=script[return _score/log(1.1 + sqrt(pow(_source.userLoc.coordinates[0] - _source.loc.coordinates[0],2)+pow(_source.userLoc.coordinates[1] - _source.loc.coordinates[1],2)));], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[NullPointerException[null]]; }{[H94j5eYQRXantctqOKMduw][merchantindex][3]: QueryPhaseExecutionException[[merchantindex][3]: query[function score (null,function=script[return _score/log(1.1 + sqrt(pow(_source.userLoc.coordinates[0] - _source.loc.coordinates[0],2)+pow(_source.userLoc.coordinates[1] - _source.loc.coordinates[1],2)));], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[NullPointerException[null]]; }{[H94j5eYQRXantctqOKMduw][merchantindex][4]: QueryPhaseExecutionException[[merchantindex][4]: query[function score (null,function=script[return _score/log(1.1 + sqrt(pow(_source.userLoc.coordinates[0] - _source.loc.coordinates[0],2)+pow(_source.userLoc.coordinates[1] - _source.loc.coordinates[1],2)));], params [null])],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[NullPointerException[null]]; }]",
"status": 500
}
请启发我,先生!!
答案 0 :(得分:0)
我已经解决了。对于脚本评分,请记住检查空值。如果为null,则可以用1替换该值。