问题
I am trying to run a straight forward Function Score Query in elasticsearch as:
{
"function_score": {
"query": {
"term": {
"timestamp": {
"value": 1396361509,
"boost": 0.05
}
}
},
"script_score": {
"script": "abs(1396361509 - doc['timestamp'].value)"
}
}
}
but I keep getting an error saying that there is no parser for "function_score":
SearchParseException[[test_index][4]: from[-1],size[-1]: Parse Failure [No parser for element [function_score]]]; }{[PKoYz4OLTbOWb6ziP8AIaQ][test_index][1]: SearchParseException[[test_index][1]: from[-1],size[-1]: Parse Failure [Failed to parse source
I am using elasticsearch 1.1.1 and tried running it via curl call, from elastic-head, and via a JAVA API. Results are always the same!
回答1:
Disclaimer: This was extracted from the question
The function score should itself be wrapped in a query! Here is an example:
{
"query": {
"bool" : {
"should" : {
"function_score" : {
"query" : {
"match_all" : { }
},
"script_score" : {
"script" : "_score * 1/abs(1396361509-doc['timestamp'].value)"
}
}
},
"boost" : 0.05
}
}
来源:https://stackoverflow.com/questions/23474216/function-score-query-elasticsearch-parsing-error