title: Elasticsearch sorting by custom item weight
body: <p>I have stored the documents which include status property. I would like to sort the documents by status priority (not status alphabetically). I have followed previous answers and composed the following function which still doesnt work as expected; the documents are sorted by status names (alphabetically):</p>
  
  <pre><code>function getESSortingByStatusQuery(query, order) {
          let statusOrder = ['BLUE', 'RED', 'BLACK', 'YELLOW', 'GREEN'];
          if(order == 'desc'){
              statusOrder.reverse();
          }
          const functions = statusOrder.map((item) =&gt; {
              const idx = statusOrder.indexOf(item);
              return {filter: {match: {statusColor: item}},
                  weight: (idx + 1) * 50}
          });
          const queryModified = {
              "function_score": {
                  "query": {"match_all": {}}, // this is for testing purposes and should be replaced with original query
                  "boost": "5",
                  "functions": functions,
                  "score_mode": "multiply",
                  "boost_mode": "replace"
              }
          }
          return queryModified;
      }
  </code></pre>
  
  <p>I would be thankful if anyone suggested the way to sort items according to predefined priority of the property (in this case status).</p>