简体   繁体   English

Elasticsearch function_score无法正常工作?

[英]Elasticsearch function_score not working?

I'm using the following function score for outfits purchased: 我对购买的服装使用以下功能评分:

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

} }

However, when I create a search - I get the following error: 但是,当我创建搜索时-出现以下错误:

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

The syntax is correct for the search as I've run it locally and it works perfectly. 语法对于搜索是正确的,因为我已经在本地运行了它,并且效果很好。 I'm now running it on my server and it's not workings. 我现在正在服务器上运行它,但无法正常工作。 Do I need to define purchased as an integer somewhere or is this due to something else? 我需要在某个地方将购买的商品定义为整数,还是由于其他原因?

The purchased field is an analyzed string field, hence the error you see. purchased字段是一个分析的字符串字段,因此会出现错误。

When indexing your documents, make sure that the numbers are not within double quotes, ie 在为文档建立索引时,请确保数字不在双引号内,即

Wrong:
{
    "purchased": "324"
}

Right:
{
    "purchased": 324
}

...or if you can't change the source documents (because you're not responsible for producing them), make sure that you create a mapping that defines the purchased field as being an integer field. ...或者如果您不能更改源文档(因为您不负责生成它们),请确保您创建了一个映射,将已purchased字段定义为整数字段。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM