title: Sorting in ElasticSearch using NodeJS Client
body: <p>I'm trying to sort the results from a query based on a field, and for some reason, it never sorts properly.  Below is the example of the query:</p>
  
  <pre><code>  starting request {
     "method": "POST",
     "path": "/index/library/_search",
     "query": {
        "from": 0,
        "size": 10,
        "sort": "[{\"title\":{\"order\":\"asc\"}}]",
        "q": "\"rules\""
       }
     }
  </code></pre>
  
  <p>Which generates this URL:</p>
  
  <p><a href="http://localhost:9200/index/library/_search?from=0&amp;size=10&amp;sort=%5B%7B%22title%22%3A%7B%22order%22%3A%22asc%22%7D%7D%5D&amp;q=%22rules%22" rel="nofollow noreferrer">http://localhost:9200/index/library/_search?from=0&amp;size=10&amp;sort=%5B%7B%22title%22%3A%7B%22order%22%3A%22asc%22%7D%7D%5D&amp;q=%22rules%22</a></p>
  
  <p>I've tried a number of different ways of structuring the sort, but for whatever reason, it never returns in alphabetical order.  </p>
  
  <p>Am I structuring the sort portion incorrectly?  Or am I missing something?</p>
  
  <p>Edit:  </p>
  
  <pre><code>    search(type, query, options) {
      let params = {
          index: this.indexName,
          type: type,
          from: options.from || 0,
          size: options.size || 500,
          sort: options.sort
      };
  
  
      if (JSON.parse(query).hasOwnProperty('query')) {
          params.body = query;
      } else {
          params.q = query;
      }
  
      return this.client.search(params);
  }
  </code></pre>
  
  <p>Query:</p>
  
  <pre><code>Elasticsearch DEBUG: 2017-05-04T15:55:00Z
  starting request {
    "method": "POST",
    "path": "/index/library/_search",
    "query": {
      "from": 0,
      "size": 10,
      "sort": "title : asc",
      "q": "rules"
    }
  }
  
  
  Elasticsearch TRACE: 2017-05-04T15:55:00Z
   -&gt; POST http://localhost:9200/index/library/_search?
    from=0&amp;size=10&amp;sort=title%20%3A%20asc&amp;q=rules
  </code></pre>