Skip to content

Rescore doesn't support multiple queries #2088

Closed
@gmoskovicz

Description

@gmoskovicz

Rescore implementation currently only support a single query. When you use the fluent API you can only add a single rescore query. If you add multiple queries, a single one will be added.

Easy repro:

            // NameScoreFunction its just a customer FunctionScoreFunctionBase implementation

            var searchresults =
                client.Search<Session>(q => q
                      .Query(mainQuery)
                      .Rescore(r => r.RescoreQuery(rq => rq
                                .Query(qq => qq
                                        .FunctionScore(fs => fs
                                            .Functions(new[] { new NameScoreFunction() { QueryName = "fullname", Field = "fullName" } })
                                ))
                                .QueryWeight(0)
                                .RescoreQueryWeight(1))
                                .WindowSize(200)
                            )
                            .Rescore(r2 => r2
                                .RescoreQuery(rq => rq
                                    .Query(qq => qq
                                        .FunctionScore(fs => fs
                                            .Functions(new[] { new NameScoreFunction() { QueryName = "company name", Field = "companyNames" } 
                                    })))
                                    .QueryWeight(.5)
                                    .RescoreQueryWeight(.5))
                                .WindowSize(200)));

The result of this is the following:

{
    "rescore": {
        "window_size": 200,
        "query": {
            "rescore_query": {
                "function_score": {
                    "functions": [{
                        "name_score": {
                            "field": "companyNames",
                            "query_name": "company name"
                        }
                    }]
                }
            },
            "query_weight": 0.5,
            "rescore_query_weight": 0.5
        }
    },
    "query": {
        "match": {
            "primary_name": {
                "query": "Joe Shmo"
            }
        }
    }
}

Note that the field is companyNames which comes from the second rescore query.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions