Sort

Sort by size of text field

{
   "query": {
      "exists": {
        "field": "messageContent.keyword"
      }
   },
   "sort": {
      "_script": {
         "script": "doc['messageContent.keyword'].value.length()",
         "type": "number",
         "order": "desc"
      }
   }
}

Number of messages per X

{
   "query": {
      "exists": {
        "field": "messageContent.keyword"
      }
   },
   "sort": {
      "_script": {
         "script": "doc['messageContent.keyword'].value.length()",
         "type": "number",
         "order": "desc"
      }
   }
}