title: How to sort based on multiple fields with Go olivere/elastic
body: <p>I've been trying for days to know how to sort based on multiple fields with Go <a href="https://github.com/olivere/elastic" rel="nofollow noreferrer"><code>olivere/elastic</code></a>. I'm trying to translate this into Go</p>
  <pre><code>{
      &quot;sort&quot; : [
          &quot;name&quot;,
          { &quot;age&quot; : &quot;desc&quot; },
      ],
  }
  </code></pre>
  <p>I've tried to use the <code>NewFieldSort()</code> and give some <code>SortBy()</code> in the Search Service. It works fine with one <code>SortBy()</code> but won't work with two <code>SortBy()</code>. It returns <code>Error 400 (Bad Request): all shards failed [type=search_phase_execution_exception]</code></p>
  <p>Here's my code</p>
  <pre><code>    sortQuery1 := elastic.NewFieldSort(&quot;name&quot;)
      sortQuery2 := elastic.NewFieldSort(&quot;age&quot;).Desc()
  
      searchService := esclient.Search().
          Index(&quot;students&quot;).
          SortBy(sortQuery1).
          SortBy(sortQuery2)
  
      searchResult, err := searchService.Do(ctx)
  </code></pre>
  <p>Do you guys have any suggestions on what to try? Thanks in advance!</p>