Hi Ben,
if I understand your ask correctly, I believe you can use "score_mode" : "sum"
in the nested query and wrap the inner term
queries on the sub-fields in a constant score. Here's a short example:
PUT my_index
{
"mappings": {
"properties": {
"user": {
"type": "nested"
}
}
}
}
PUT my_index/_doc/1
{
"group" : "fans",
"user" : [
{
"first" : "john",
"last" : "smith"
},
{
"first" : "john",
"last" : "white"
},
{
"first" : "robert",
"last" : "white"
}
]
}
PUT my_index/_doc/2
{
"group" : "fans",
"user" : [
{
"first" : "john",
"last" : "smith"
},
{
"first" : "john",
"last" : "white"
},
{
"first" : "john",
"last" : "snow"
}
]
}
POST my_index/_search
{
"from": 0,
"size": 30,
"query": {
"nested": {
"score_mode": "sum",
"query": {
"constant_score": {
"boost": 100,
"filter": {
"term": {
"user.first": {
"value": "john"
}
}}
}
},
"path": "user"
}
}
}
When I try the above on Elasticsearch 7.5 I get:
"hits" : [
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "2",
"_score" : 300.0,
"_source" : {
"group" : "fans",
"user" : [
{
"first" : "john",
"last" : "smith"
},
{
"first" : "john",
"last" : "white"
},
{
"first" : "john",
"last" : "snow"
}
]
}
},
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 200.0,
"_source" : {
"group" : "fans",
"user" : [
{
"first" : "john",
"last" : "smith"
},
{
"first" : "john",
"last" : "white"
},
{
"first" : "robert",
"last" : "white"
}
]
}
}
]
}
Maybe this is not exactly what you need but you can hopefully work from there...
Cheers