功能评分查询弹性搜索解析错误 [英] Function Score Query elasticsearch parsing error

查看:107
本文介绍了功能评分查询弹性搜索解析错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在弹性搜索中运行一个直接的函数得分查询:

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)"
  }
}
}

但我不断收到一个错误,说有没有解析function_score:

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

我正在使用弹性搜索1.1.1,并尝试通过curl调用,从弹性头和通过JAVA API运行它。结果总是一样的!

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!

推荐答案

免责声明:这是从问题

功能分数本身应该包含在查询中!这是一个例子:

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
  }
}

这篇关于功能评分查询弹性搜索解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆