Problem with fuction_score and field_value_factor

Hi all, I have a problem with a query

GET score-score-score/_search
{
  "query": {
    "function_score": {
        "query": {
          "bool": {
            "must": [
              {"term": { "validity": true }},
              {"term": { "status": true }}
            ]
          }
        },
        "functions": [
          {
            "field_value_factor": {
              "field": "title",
              "factor": 1.2
            }
          }
        ]
    }
  }
}

When I do that I have this error

{
  "error" : {
    "root_cause" : [
      {
        "type" : "query_shard_exception",
        "reason" : "failed to create query: class org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData cannot be cast to class org.elasticsearch.index.fielddata.IndexNumericFieldData (org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData and org.elasticsearch.index.fielddata.IndexNumericFieldData are in unnamed module of loader 'app')",
        "index_uuid" : "mpqIAacMRtmoX-2x13eTnw",
        "index" : "score-score-score"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "score-score-score",
        "node" : "2RANfoHuSJOh6X026UYfog",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "failed to create query: class org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData cannot be cast to class org.elasticsearch.index.fielddata.IndexNumericFieldData (org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData and org.elasticsearch.index.fielddata.IndexNumericFieldData are in unnamed module of loader 'app')",
          "index_uuid" : "mpqIAacMRtmoX-2x13eTnw",
          "index" : "score-score-score",
          "caused_by" : {
            "type" : "class_cast_exception",
            "reason" : "class org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData cannot be cast to class org.elasticsearch.index.fielddata.IndexNumericFieldData (org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData and org.elasticsearch.index.fielddata.IndexNumericFieldData are in unnamed module of loader 'app')"
          }
        }
      }
    ]
  },
  "status" : 400
}

The mapping is really simple. It's to test the function_score

{
  "score-score-score" : {
    "mappings" : {
      "properties" : {
        "content" : {
          "type" : "keyword"
        },
        "status" : {
          "type" : "boolean"
        },
        "title" : {
          "type" : "keyword"
        },
        "validity" : {
          "type" : "boolean"
        }
      }
    }
  }
}

Do you have an idea? Do I miss something?
Thanks a lot

field_value_factor function expects a numeric field that can return a numeric value, while you provided title field of the keyword type.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.