【问题标题】:Elasticsearch function_score not working?Elasticsearch function_score 不起作用?
【发布时间】:2018-03-11 08:55:58
【问题描述】:

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

{
"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."

搜索的语法是正确的,因为我在本地运行它并且它运行良好。我现在在我的服务器上运行它,但它不起作用。我需要在某处将购买定义为整数还是由于其他原因?

【问题讨论】:

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


    【解决方案1】:

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

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

    Wrong:
    {
        "purchased": "324"
    }
    
    Right:
    {
        "purchased": 324
    }
    

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

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

    【讨论】:

    • 这个运气好吗?
    猜你喜欢
    • 2017-02-03
    • 1970-01-01
    • 2016-02-01
    • 2018-10-07
    • 2019-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-24
    相关资源
    最近更新 更多