Unable to retrieve field value from Doc Values in nested function_score query

Hi all,

We are using function_score query to sort search results. The score takes into account the value of a field in the indexed document. However, it appears the field value can not be properly retrieved from Doc Values, it always returns '0' although the actual value is otherwise.

Here I prepared some documents and query to illustrate the problem, you may try it out in CONSOLE.

As the example shows the field 'reward_factor' in the indexed document is populated with non zero value, however, when it's retrieved using doc['reward_factor'].value, it is alway '0'. Tried other ways to retrieve the value, such as _fields (as documented here), no success.

One thing maybe special here is that the function_score query is under a 'nested' query, in such case, are we not able to retrieve the field value? No documentation seems indicating so.

Much appreciated if someone could help with this.

Junjun

PS: Elasticsearch version: 5.1.1

hi,

I would say that the function_score is only applied on the nested documents, so the reward_factor is not accessible

see if it can helps:


bye,
Xavier

Thank you Xavier for your answer. It makes sense although I do wish there is a way to get the field value from parent docs. I guess I have a walk-around that is to include 'reward_factor' field in each of the nested subdocuments. Not very elegant, but it should work.
Cheers,
Junjun

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