Elasticsearch function_score不工作?

时间:2017-09-29 12:41:22

标签: ruby-on-rails ruby elasticsearch search filter

我对购买的服装使用以下功能评分:

{
"query": {
    "function_score": {
        "field_value_factor": {
            "field": "purchased",
            "factor": 1.2,
            "modifier": "sqrt",
            "missing": 1
        }
    }
}

}

但是,当我创建搜索时 - 出现以下错误:

"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [purchased] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."

语法对于搜索是正确的,因为我在本地运行它并且它完美地运行。我现在正在我的服务器上运行它并不适用。我是否需要在某处将购买定义为整数,或者这是由于其他原因?

1 个答案:

答案 0 :(得分:0)

purchased字段是一个已分析的字符串字段,因此您会看到错误。

索引文档时,请确保数字不在双引号内,即

Wrong:
{
    "purchased": "324"
}

Right:
{
    "purchased": 324
}

...或者如果您无法更改源文档(因为您不负责生成源文档),请确保创建将purchased字段定义为的映射整数字段。

{
    "your_type": {
        "properties": {
            "purchased": {
                "type": "integer"
            }
        }
    }
}