# Field\_value\_factor wrong depending on index

**URL:** <https://discuss.elastic.co/t/field-value-factor-wrong-depending-on-index/215567>\
**Category:** Elasticsearch\
**Created:** [January 18, 2020, 4:38pm UTC](https://discuss.elastic.co/t/field-value-factor-wrong-depending-on-index/215567 "2020-01-18T16:38:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicolas-t](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@nicolas-t](https://discuss.elastic.co/u/nicolas-t)\
**Post date:** [January 18, 2020, 4:38pm UTC](https://discuss.elastic.co/t/field-value-factor-wrong-depending-on-index/215567/1 "2020-01-18T16:38:46Z")

</div>

Hello,

I have two similar documents in two different indices.  
My score is correct in only one of them.

This is my document :

```
{
  "id": 1,
  "colors": {
    "colorA": {
      "hue": 50,
      "population": 0.5
    },
    "colorB": {
      "hue": 90,
      "population": 0.00003
    },
  }
}

```

I want to use `population` as the score when one color matches my query.

I'm using `field_value_factor` in my query like this :

```
{
  "query": {
    "nested": {
      "path": "colors",
      "query": {
        "function_score": {
          "query": {
            "match": {
              "colors.colorA.hue": 50
            }
          },
          "field_value_factor": {
            "field": "colors.colorA.population"
          },
          "boost_mode": "replace"
        }
      }
    }
  }
}

```

* * *

If I use the explain API on a "new" index I get the correct score of **0.5** :

```
"value": 0.5,
"description": "min of:",
"details": [
    {
      "value": 0.5,
      "description": "field value function: none(doc['colors.colorA.population'].value * factor=1.0)",
      "details": []
    }, ...
]
...

```

But if I do the same on an index containing many other similar documents I get a wrong score of **0** :

```
"value": 0,
"description": "min of:",
"details": [
    {
      "value": 0,
      "description": "field value function: none(doc['colors.colorA.population'].value * factor=1.0)",
      "details": []
    }, ...
]
...

```

* * *

Strangely, if I change the field to color **B**.population

```
"field_value_factor": {
  "field": "colors.colorB.population"
},

```

I get the expected behaviour (score of **0.00003** ) :

```
"value": 0.00003,
"description": "min of:",
"details": [
    {
      "value": 0.00003,
      "description": "field value function: none(doc['colors.colorA.population'].value * factor=1.0)",
      "details": []
    }, ...
]
...

```

* * *

I've made a lot of tries but I can't quite understand why is my score wrong when I use `colors.colorA.population` and not `colors.colorB.population`, and why is it working on a "new" index but not on another one ?

This issue seems related to mine: [Field value factor ignoring fields with a value less than one](https://discuss.elastic.co/t/field-value-factor-ignoring-fields-with-a-value-less-than-one/30034)  
But I create my index I use the type `nested` for my colors array.

Thanks for your help

---

<div class="post-metadata">

**Author:** ![nicolas-t](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@nicolas-t](https://discuss.elastic.co/u/nicolas-t)\
**Post date:** [January 18, 2020, 9:53pm UTC](https://discuss.elastic.co/t/field-value-factor-wrong-depending-on-index/215567/2 "2020-01-18T21:53:28Z")

</div>

Hello,

I fixed it, by using a `object` datatype instead of `nested`, and by typing every properties of these object.

The issue was the same as the one described here :

> [@Field value factor ignoring fields with a value less than one](https://discuss.elastic.co/t/field-value-factor-ignoring-fields-with-a-value-less-than-one/30034):
>
> I'm having difficulty getting function scoring to work when the value is between zero and one (fractional). I want to use a reciprocal/inverse scoring function on these documents where 0.1 would be high and 10+ would be low. However, the function score query appears to ignore any document with a value less than 1. See here example queries and document: Any ideas what causes this or if there is a parameter I'm missing to get the function score to consider these documents? Thank you.

---

<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:** [February 15, 2020, 10:08pm UTC](https://discuss.elastic.co/t/field-value-factor-wrong-depending-on-index/215567/3 "2020-02-15T22:08:14Z")

</div>

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