How to specify routing key in spring data elasticsearch during indexing.
I have made a spring boot application which uses spring data elasticsearch to index documents.
Below is my document structure(without getters setters).
@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;
}
This is the code for indexing a document. I'm using ElasticSearchTemplate to index my data.
public void saveAll(List<EsDocument> esDocuments) {
List<IndexQuery> queries = new ArrayList<>();
for(EsDocument esDocument : esDocuments) {
IndexQuery indexQuery = new IndexQuery();
indexQuery.setObject(esDocument);
indexQuery.setIndexName(esDocument.getGroup());
queries.add(indexQuery);
}
if (queries.size() > 0) {
elasticsearchTemplate.bulkIndex(queries);
}
logger.info("Batch Documents Saved to elastic search");
}
Now how to add custom routing key during indexing?. I want to add filters.order_id as my routing key during indexing.