Sort Based on text Position from multiple fields

  {
      "size": 100,
      "_source": {
        "includes": [
          "id",
          "name",
          "type",
          "acc_names"
        ]
      },
      "query": {
        "match_phrase_prefix": {
          "name_factor": {
            "query": "text"
          }
        }
      },
      "sort": {
        "_script": {
          "type": "number",
          "script": {
//Make source in one line
            "source": "def text='text';
                       if (doc['name'].value.toLowerCase().indexOf(text)!=-1){
                         doc['name'].value.toLowerCase().indexOf(text)
                       }else{
                          for(an in doc['acc_names'].values) {
                            if (an.toLowerCase().indexOf(text)!=-1) 
                                return an.toLowerCase().indexOf(text)}}"
          },
          "order": "asc"
        }
      }
    }

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