# Ability to use function\_score with the value of a nested tag

**URL:** <https://discuss.elastic.co/t/ability-to-use-function-score-with-the-value-of-a-nested-tag/184434>\
**Category:** Elasticsearch\
**Created:** [June 5, 2019, 5:50pm UTC](https://discuss.elastic.co/t/ability-to-use-function-score-with-the-value-of-a-nested-tag/184434 "2019-06-05T17:50:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenkiers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenkiers/32/47578_2.png) [@stephenkiers](https://discuss.elastic.co/u/stephenkiers)\
**Post date:** [June 5, 2019, 5:50pm UTC](https://discuss.elastic.co/t/ability-to-use-function-score-with-the-value-of-a-nested-tag/184434/1 "2019-06-05T17:50:01Z")

</div>

I have a index that looks like this stripped down example:

```
{
  "elastic-demo": {
    "mappings": {
      "demo_index": {
        "properties": {
          "id": {
            "type": "text",
            "index": false
          },
          "score": {
            "type": "long"
          },
          "tags": {
            "type": "nested",
            "properties": {
              "label": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "my_boost": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "tag": {
                "properties": {
                  "label": {
                    "type": "keyword"
                  },
                  "my_boost": {
                    "type": "double"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

```

and I would like to search for a tag "test" and have the tag that matches the search's `my_boost` be multiplied by the main doc's `score`.

So for example,  
I search for "test"

```
{
  "from":0,
  "size": 5,
  "query": {
    "nested": {
      "path": "tags",
      "score_mode": "avg",
      "query": {
        "bool": {
          "must": [{
            "match": {
              "tags.label": "test"
            }
          }]
        }
      }
    }
  }
}

```

and I get results

```
{
  "took": 2,
  "timed_out": false,
  "hits": {
    "total": 1,
    "max_score": 7.690165,
    "hits": [
      {
        "_index": "demo_indices",
        "_type": "demo_index",
        "_id": "abcd",
        "_score": 7.690165,
        "tags": [
          {
            "label": "test",
            "my_boost": 6,
            "approved_by_owner": false
          }
        ],
        "score": 100
      }
    ]
  }
}

```

I actually want the score to be `score` \* `boost * _score`; so `100 * 6 * 7.690165 = 4614`

Does that make sense? Can it be done? I feel like [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor) is what I am looking for, but I can't figure out how to get the specific nested tag

Thanks in advance

---

<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:** [July 3, 2019, 8:04pm UTC](https://discuss.elastic.co/t/ability-to-use-function-score-with-the-value-of-a-nested-tag/184434/3 "2019-07-03T20:04:53Z")

</div>

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