majran
majran

Reputation: 469

script_score returns 0 in elastic 1.3 using lang groovy

I am new in elastic. I am using function_score to customize the score. here is my code:

body = {
        "from" : product_per_page*page,
        "size" : product_per_page,
        "query": {
            "function_score": {
                "query": {
                    "bool":{
                        "must": [
                            {
                                "range": {
                                    "price": {
                                        "gte": from_price,
                                        "lte": to_price
                                        }
                                    }
                            }, {
                                "match":{
                                    "text": {
                                        "query": query,
                                        }
                                    },
                                }
                            ]
                        },
                    },
                "script_score": {
                    "script": "floor(_score)*doc['boost'].value",
                    "lang":"groovy"
                    },
                "boost_mode": "replace",
                },
            }
        }

the problem is that the score always return 0.0. when I set script to:

"script": "_score"

It will return the correct score like 0.98977035 (a number between 0.0 and 1.0). also when set to:

"script": "_score + 0.0001"

again it returns correct. but when I use this:

"script": "_score + 1"

it returns 1.0 or:

"script": "_score *10"

returns 0.0(and any function I use such "script": "floor(_score)" returns 0.0). also:

"script": "doc['boost'].value"

returns 0.0 (doc['boost'].value is between 10 , 100)

I also tried:

"script": "32"

and it returns 32 (as I expected).so I guess that the problem is groovy. maybe when the numbers are big,they round to 0.0. what should I do? thanks

Upvotes: 3

Views: 183

Answers (1)

majran
majran

Reputation: 469

I found the solution but not the problem! if I use floor( _score*10.0 ) it will return the correct answer!(I don't know why) and about "script": "doc['boost'].value" It convert float to Integer(I could not solve the problem for float yet).

Upvotes: 2

Related Questions