# Compile error when trying to use tf() in script\_score

**URL:** <https://discuss.elastic.co/t/compile-error-when-trying-to-use-tf-in-script-score/99467>\
**Category:** Elasticsearch\
**Created:** [September 5, 2017, 6:00pm UTC](https://discuss.elastic.co/t/compile-error-when-trying-to-use-tf-in-script-score/99467 "2017-09-05T18:00:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mundek88](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@mundek88](https://discuss.elastic.co/u/mundek88)\
**Post date:** [September 5, 2017, 6:00pm UTC](https://discuss.elastic.co/t/compile-error-when-trying-to-use-tf-in-script-score/99467/1 "2017-09-05T18:00:21Z")

</div>

Hi,  
my mappings currently looks like this (Python code)

```auto
{
	'meeting': {
        'properties': {
            'user': {'type': 'float'},
            'subject': {'type': 'string',},
            'notes': {'type': 'text'},
            'created': {'type': 'date', 'format': 'yyyy/MM/dd HH:mm:ss'},
        }
    }
}
body = {'mappings': mappings}
return es.indices.create(index=INDEX_NAME, body=body)

```

and I'm trying to make a query:

```auto
search_query = {
"query": {

    "function_score": {
    "functions": [
    {  
        "script_score": {
            "script": "_score * doc['subject'][Something].tf()"
        } 
    }],

        "query": {
            "bool": {
                "must": [
                    {
                        "multi_match": {
                            "query": keyword,
                            "fields": [
                                "notes^5",
                            ]
                        },
                    },
                    {
                        "term": {
                            "user": USER_ID,
                        },
                    },
                    {
                        "range": {
                            "created": {
                                "gte": created_gte,
                            }
                        },
                    },
                ],
            },
        },
    },
}
}

```

My problem is with `script_score` part. After adding it i've got `TransportError(400, 'search_phase_execution_exception', 'compile error')`  
What I;m doing wrong?  
Elasticsearch version: 5.1.2

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [September 5, 2017, 7:24pm UTC](https://discuss.elastic.co/t/compile-error-when-trying-to-use-tf-in-script-score/99467/2 "2017-09-05T19:24:27Z")

</div>

I think you are confusing `doc` with `_index`. See [https://www.elastic.co/guide/en/elasticsearch/reference/5.1/modules-advanced-scripting.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/modules-advanced-scripting.html).

Also note that `_index` has been removed for Elasticsearch 6.0. You can see the updated docs which explain how to write a plugin to gain access to Lucene internals:  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.5/modules-scripting-engine.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/modules-scripting-engine.html)

---

<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:** [October 3, 2017, 7:24pm UTC](https://discuss.elastic.co/t/compile-error-when-trying-to-use-tf-in-script-score/99467/3 "2017-10-03T19:24:39Z")

</div>

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