Function Score Query elasticsearch parsing error

烂漫一生 提交于 2019-12-10 10:19:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!