Sort the Elasticsearch results based on the matched nested object in search-ui

I want to implement it in Search-UI. How should I do it? For instance, if users search for 'Mucopolysaccharidosis Type 1,' I want to sort the results based on the "score" of the matched nested condition inside this field 'medifind_condition_scores.' I have this query working in the Kibana DevTools.

Working query:

{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "medifind_conditions": "Mucopolysaccharidosis Type 1"
        }
      },
      "functions": [
        {
          "script_score": {
            "script": {
              "source": "double score = 0; for (item in params['_source']['medifind_condition_scores']) { if (item['condition'] == params.condition) { score = item['score']; break; } } return score;",
              "params": {
                "condition": "Mucopolysaccharidosis Type 1"
              }
            }
          }
        }
      ],
      "boost_mode": "replace"
    }
  }
}

This field, 'medifind_condition_scores,' will be present in each result. Sometimes, other results may not have this field.

 "medifind_condition_scores": [
 {
           "score": 96.99005856745995,
           "condition": "Mucopolysaccharidosis Type 1"
 },
{
           "score": 95.92013152310234,
           "condition": "Mucopolysaccharidoses"
},

Essentially, I want to implement the working query above in Search-UI, but I don't know how to do it. Or, is it possible to make this sorting in Search-UI itself?

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