Elasticsearch Script_score


(Lifo888) #1

Hi,

I'm trying to run a match query and get the result sorted based on the term frequency only, but 'im having some difficulty forming the query. I have the following script query but am getting the following exception when i try to run it.

{
"error" : "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[jp7D_tr5TV6bSbiBCTlxsg][my_index][0]: RemoteTransportException[[Loss][inet[]][indices:data/read/search[phase/query]]]; nested: QueryPhaseExecutionException[[my_index][0]: query[filtered(function score (headline:long,function=script[_index[headline][long].tf()], params [null]))->cache(_type:my_type)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: headline for class: ed6b97f80038ada8c3d6e5ceec691bb004ec6de0]]; }{[SpJJIZdRQ5ePUYkjpeQsGQ][my_index][1]: QueryPhaseExecutionException[[my_index][1]: query[filtered(function score (headline:long,function=script[_index[headline][long].tf()], params [null]))->cache(_type:my_type)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: headline for class: ed6b97f80038ada8c3d6e5ceec691bb004ec6de0]]; }{[jp7D_tr5TV6bSbiBCTlxsg][my_index][2]: RemoteTransportException[[Loss][inet[]][indices:data/read/search[phase/query]]]; nested: QueryPhaseExecutionException[[my_index][2]: query[filtered(function score (headline:long,function=script[_index[headline][long].tf()], params [null]))->cache(_type:my_type)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: headline for class: ed6b97f80038ada8c3d6e5ceec691bb004ec6de0]]; }{[SpJJIZdRQ5ePUYkjpeQsGQ][my_index][3]: QueryPhaseExecutionException[[my_index][3]: query[filtered(function score (headline:long,function=script[_index[headline][long].tf()], params [null]))->cache(_type:my_type)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: headline for class: ed6b97f80038ada8c3d6e5ceec691bb004ec6de0]]; }{[SpJJIZdRQ5ePUYkjpeQsGQ][my_index][4]: QueryPhaseExecutionException[[my_index][4]: query[filtered(function score (headline:long,function=script[_index[headline][long].tf()], params [null]))->cache(_type:my_type)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: headline for class: ed6b97f80038ada8c3d6e5ceec691bb004ec6de0]]; }]",
"status" : 500
}

curl -XGET 'deva01:9800/my_index/my_type/_search?pretty' -d '
{
    "_source": [
        "headline"
    ],
    "query": {
        "filtered": {
            "query": {
                "function_score": {
                    "query": {
                        "match": {
                            "headline": "long"
                        }
                    },
                    "boost_mode": "replace",
                    "functions": [
                        {
                            "script_score": {
                                "script": "_index['headline']['long'].tf()"
                            }
                        }
                    ]
                }
            }
        }
    },
    "size": 10,
    "track_scores": true
}
'

Does anyone know what is wrong with my query? Sorry if i missed soemthing obvious, this is my first time running scripting query on ES.

Thanks!


(system) #2