查询时如何将参数传递给相似性脚本函数

时间:2019-04-29 09:08:59

标签: elasticsearch

在配对中,公式2 *配对数/配对对* 100 例如:santhoshi在具有弹性索引的文档值中,并且santhosh是查询中的searchin元素,然后santhoshi中的对数= 8,匹配的对数= 7,santhosh中的对数= 7     结果= 2 * 7 /(7_8)* 100 = 93%...     我尝试了下面的代码,将.sumDocFreq提交为“类型”:“ illegal_argument_exception,”原因”:“未定义变量[field]。”

{ "query": {
        "function_score": {
             "query": {
              "match": {
                "Name":"santhosh"
              }
            },
             "min_score":100,
            "functions": [
                {
                    "script_score": {
                         "script": {
                        "params" : {
                            "inputpairlength": 6 },
                        "source": "double tf = doc.freq; double ttf = field.sumDocFreq;  return (2* tf /(params.inputpairlength + ttf)) * 100;"
                         }
                    }
                }
            ]
        }
    }

}

 "settings": {
      "similarity": {
      "scripted_tfidf": {
        "type": "scripted",
        "script": {
          "source": "double tf = doc.freq; double ttf = field.sumDocFreq;  return  tf / (params.inputpairlength+ttf) * 100;"
        }
      }
    },
getting param.input is not defined


I need to pass parameter and calcluate score using  this "double tf = doc.freq; double ttf = field.sumDocFreq;  return  tf / (params.inputpairlength+ttf) * 100

1 个答案:

答案 0 :(得分:0)

这是访问字段统计信息的错误方法。访问字段统计信息-

_index ['FIELD']。docCount()

您可以在此处详细了解-Elastic Guide