# Problem with fuction\_score and field\_value\_factor

**URL:** <https://discuss.elastic.co/t/problem-with-fuction-score-and-field-value-factor/274330>\
**Category:** Elasticsearch\
**Created:** [May 28, 2021, 11:11am UTC](https://discuss.elastic.co/t/problem-with-fuction-score-and-field-value-factor/274330 "2021-05-28T11:11:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Biiru](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/biiru/32/89404_2.png) [@Biiru](https://discuss.elastic.co/u/Biiru)\
**Post date:** [May 28, 2021, 11:11am UTC](https://discuss.elastic.co/t/problem-with-fuction-score-and-field-value-factor/274330/1 "2021-05-28T11:11:33Z")

</div>

Hi all, I have a problem with a query

```auto
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

```auto
{
  "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

```auto
{
  "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

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [May 28, 2021, 9:17pm UTC](https://discuss.elastic.co/t/problem-with-fuction-score-and-field-value-factor/274330/2 "2021-05-28T21:17:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 25, 2021, 9:18pm UTC](https://discuss.elastic.co/t/problem-with-fuction-score-and-field-value-factor/274330/3 "2021-06-25T21:18:17Z")

</div>

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