Apply minimum score parameter for the child queries

I'm trying to apply some minimum score criteria for my has child queries, my data looks like this:

{"Product Code": "A",
"properties" :[{"PROPERTY_NAME":"density","PROPERTY_NAME Encoded":[0.22,0.432,.....],"value":"low"}, 
               {"PROPERTY_NAME":"tensile modulus","PROPERTY_NAME Encoded":[0.54,0.134,...],"value":"low"}, 
               {"PROPERTY_NAME":"humidity absorption","PROPERTY_NAME Encoded":[0.671,0.321,....],"value":"high"}],
"application": ["example applications of A"]
},

{"Product Code": "B",
"properties" :[{"PROPERTY_NAME":"density","PROPERTY_NAME Encoded":[-0.123,0.324,...],"value":"medium"}, 
               {"PROPERTY_NAME":"tensile modulus","PROPERTY_NAME Encoded":[0.516,0.812,....],"value":"high"}, 
               {"PROPERTY_NAME":"humidity absorption","PROPERTY_NAME Encoded":[0.46,0.25,...],"value":"medium"}],
"application": ["example applications of B"]
}

I have defined the parent-child relationship for this data while creating the index.

When I query the index, I use vector search and use cosine similarity to get the properties,
eg:

user_query = "low solidity and high humidity absorption"

{
  'size': 20,
  'query': {
    'bool': {
      'must': [
        {
          'has_child': {
            'type': 'property',
            'score_mode': 'max',
            'inner_hits': {
              'name': 'hit_0',
            'query': {
              'bool': {
                'must': [
                  {
                    'function_score': {
                      'script_score': {
                        'script': {
                          'source': 'doc["PROPERTY_NAME Encoded"].size() == 0 ? 0 : 1.0 + 1.5*cosineSimilarity(params.vec, "PROPERTY_NAME Encoded")',
                          'params': {
                            'vec': [-0.002,-0.054,-0.0095,...]
                          }
                        }
                      }
                    }
                  }
                ],
                'should': [
                  {
                    'match': {
                      'value': {
                        'query': 'low',
                        'boost': 2
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        {
          'has_child': {
            'type': 'property',
            'score_mode': 'max',
            'inner_hits': {
              'name': 'hit_1',
            'query': {
              'bool': {
                'must': [
                  {
                    'function_score': {
                      'script_score': {
                        'script': {
                          'source': 'doc["PROPERTY_NAME Encoded"].size() == 0 ? 0 : 1.0 + 1.5*cosineSimilarity(params.vec, "PROPERTY_NAME Encoded")',
                          'params': {
                            'vec': [0.343,0.454,0,....]
                          }
                        }
                      }
                    }
                  }
                ],
                'should': [
                  {
                    'match': {
                      'value': {
                        'query': 'high',
                        'boost': 2
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

Here I have 2 separate child queries for each of the properties the user has searched for.

Since I use vector search it always gives me some results based on the cosine similarity score, and it will execute the "should" query and boost the score, I'm trying to apply some minimum threshold at each of the child queries so that, I can restrict the results if the match is not correct, and the "should" query must execute only if I have a good cosine similarity score.

Is there any way I can achieve this?

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