title: How to specify routing key in spring data elasticsearch during indexing.?
body: <p>How to specify routing key in spring data elasticsearch during indexing.</p>
  
  <p>I have made a  spring boot application which uses spring data elasticsearch to index documents. </p>
  
  <p>Below is my document structure(without getters setters).</p>
  
  <pre><code>@Document(indexName = Constants.ES_INDEX_NAME, type = Constants.ES_TYPE,createIndex = false)
  public class EsDocument {
  
      @Id
      private String ID;
  
      private String group;
  
      private String request;
  
      private String response;
  
      private Filters filters;
  
      public EsDocument() {
      }
  }
  
  public class Filters {
  
      private String order_id;
      private String api_type;
      private int status;
      private String statusCode;
      private String createdAt;
  }
  </code></pre>
  
  <p>This is the code for indexing a document. I'm using <strong>ElasticSearchTemplate</strong> to index my data.</p>
  
  <pre><code>public void saveAll(List&lt;EsDocument&gt; esDocuments) {
          List&lt;IndexQuery&gt; queries = new ArrayList&lt;&gt;();
          for(EsDocument esDocument : esDocuments) {
              IndexQuery indexQuery = new IndexQuery();
              indexQuery.setObject(esDocument);
              indexQuery.setIndexName(esDocument.getGroup());
              queries.add(indexQuery);
          }
          if (queries.size() &gt; 0) {
              elasticsearchTemplate.bulkIndex(queries);
          }
          logger.info("Batch Documents Saved to elastic search");
      }
  </code></pre>
  
  <p>Now how to add <strong>custom routing key</strong> during indexing?. I want to add <strong>filters.order_id</strong>  as my routing key during indexing.</p>