Compile error when trying to use tf() in script_score


#1

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

{
	'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:

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


(Ryan Ernst) #2

I think you are confusing doc with _index. See 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


(system) #3

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