title: Sorting in elastic search using new java api
body: <p>I am using the latest java API for communication with the elastic search server.</p>
  <p>I require to search data in some sorted order.</p>
  <pre><code>       SortOptions sort = new SortOptions.Builder().field(f -&gt; f.field(&quot;customer.keyword&quot;).order(SortOrder.Asc)).build();
      List&lt;SortOptions&gt; list = new ArrayList&lt;SortOptions&gt;();
      list.add(sort);
  
      SearchResponse&lt;Order&gt; response = elasticsearchClient.search(b -&gt; b.index(&quot;order&quot;).size(100).sort(list)
              .query(q -&gt; q.bool(bq -&gt; bq
                      .filter(fb -&gt; fb.range(r -&gt; r.field(&quot;orderTime&quot;).
                                      gte(JsonData.of(timeStamp(&quot;01-01-2022-01-01-01&quot;)))
                                      .lte(JsonData.of(timeStamp(&quot;01-01-2022-01-01-10&quot;)))
                              )
                      )
                     // .must(query)
              )), Order.class);
  </code></pre>
  <p>I have written the
  above code for getting search results in sorted order by customer.
  I am getting the below error when I run the program.</p>
  <pre><code>Exception in thread &quot;main&quot; co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [search_phase_execution_exception] all shards failed
  at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:281)
  at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:147)
  at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:1487)
  at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:1504)
  at model.OrderDAO.fetchRecordsQuery(OrderDAO.java:128)
  </code></pre>
  <p>Code runs fine if I remove <strong>.sort()</strong> method.</p>
  <p>My index is configured in the following format.</p>
  <pre><code>{
  &quot;order&quot;: {
      &quot;aliases&quot;: {},
      &quot;mappings&quot;: {
          &quot;properties&quot;: {
              &quot;customer&quot;: {
                  &quot;type&quot;: &quot;text&quot;,
                  &quot;fields&quot;: {
                      &quot;keyword&quot;: {
                          &quot;type&quot;: &quot;keyword&quot;,
                          &quot;ignore_above&quot;: 256
                      }
                  }
              },
              &quot;orderId&quot;: {
                  &quot;type&quot;: &quot;text&quot;,
                  &quot;fields&quot;: {
                      &quot;keyword&quot;: {
                          &quot;type&quot;: &quot;keyword&quot;,
                          &quot;ignore_above&quot;: 256
                      }
                  }
              },
              &quot;orderTime&quot;: {
                  &quot;type&quot;: &quot;long&quot;
              },
              &quot;orderType&quot;: {
                  &quot;type&quot;: &quot;text&quot;,
                  &quot;fields&quot;: {
                      &quot;keyword&quot;: {
                          &quot;type&quot;: &quot;keyword&quot;,
                          &quot;ignore_above&quot;: 256
                      }
                  }
              }
          }
      },
      &quot;settings&quot;: {
          &quot;index&quot;: {
              &quot;routing&quot;: {
                  &quot;allocation&quot;: {
                      &quot;include&quot;: {
                          &quot;_tier_preference&quot;: &quot;data_content&quot;
                      }
                  }
              },
              &quot;number_of_shards&quot;: &quot;1&quot;,
              &quot;provided_name&quot;: &quot;order&quot;,
              &quot;creation_date&quot;: &quot;1652783550822&quot;,
              &quot;number_of_replicas&quot;: &quot;1&quot;,
              &quot;uuid&quot;: &quot;mrAj8ZT-SKqC43-UZAB-Jw&quot;,
              &quot;version&quot;: {
                  &quot;created&quot;: &quot;8010299&quot;
              }
          }
      }
  }
  </code></pre>
  <p>}</p>
  <p>Please let me know what is wrong here also if possible please send me the correct syntax for using sort() in the new java API.</p>
  <p>Thanks a lot.</p>