Script_score query with cosineSimularity on alias

I have an alias created with several different indices and each index has multiple dense_vector fields. I want to perform a script_score search on all the dense_vector field with the cosineSimularity function.
For example:

"query": {
        "script_score": {
            "query": {
                "match_all": {}
            "script": {
                "source": "cosineSimilarity(params.query_vector, 'A_vector')+cosineSimilarity(params.query_vector, 'B_vector')+cosineSimilarity(params.query_vector, 'C_vector')+cosineSimilarity(params.query_vector, 'D_vector')+cosineSimilarity(params.query_vector, 'E_vector')+cosineSimilarity(params.query_vector, 'F_vector')+cosineSimilarity(params.query_vector, 'G_vector')+cosineSimilarity(params.query_vector, 'H_vector')+cosineSimilarity(params.query_vector, 'I_vector')",
                "params": {
                    "query_vector": [
                        0.021623458713293076, ...

The problem I encountered is that not all indices have the same vector field. Is there any way I can check if the field exist in the script and return a 0 value if field not exists?


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