Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom_score query within has_child query does not recognize child document fields within the script property #3285

Closed
apasumarthi opened this issue Jul 3, 2013 · 4 comments

Comments

@apasumarthi
Copy link

custom_score query within has_child query does not recognize child document fields within the score script.

I have two document types, "Forums" and "ForumStats". Forums is a parent type and ForumStats is a child type. I had set the mapping correctly.

When I issue query like the one below on forums type, ES complains that the field "avgPostsPerMinute" is not found in "Forums" type, which I feel is wrong as the script is supposed to look at child document fields.

Note: "avgPostsPerMinute" field belongs to ForumStats type.

{
"size": 20,
"sort": {
"_score": "desc"
},
"query": {
"has_child": {
"type": "forumstats",
"score_type": "sum",
"query": {
"custom_score": {
"script": "doc['avgPostsPerMin'].value",
"query": {
"match_all": {}
}
}
}
}
}
}

If I set the script to a value that doe snot refer to child document type, then the query runs and I get a score for the parent document correctly.

Please review this and let me know if this is by design or a bug. If it is by design, it looks odd as the custom score query is running on child documents and I would expect ES to recognize the child document fields within the script property.

Thanks & Regards,
Aditya.

@imotov
Copy link
Contributor

imotov commented Jul 3, 2013

@apasumarthi this is known issue. The script in the custom_score query inside has_child is working in context of the parent query. So, you need to use fully qualified field names:

    "custom_score": {
        "script": "doc['forumstats.avgPostsPerMin'].value",

See working example here.

@apasumarthi
Copy link
Author

Thanks Igor.

I was able to figure out the same (with little hunch). Hopefully the actual issue will be fixed soon.

@fanbiao
Copy link

fanbiao commented Jul 3, 2014

i have the same problem abount has_child

@clintongormley
Copy link

This has been fixed in #5838

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants