// generate an id for the document
String id = getIdForDoc(doc);
// create an IndexRequest for this document
IndexRequest indexRequest = new IndexRequest(index, type, id);
indexRequest.routing(request.param("routing"));
indexRequest.parent(request.param("parent"));
indexRequest.source(doc);
indexRequest.timeout(request.paramAsTime("timeout", IndexRequest.DEFAULT_TIMEOUT));
indexRequest.refresh(request.paramAsBoolean("refresh", indexRequest.refresh()));
// TODO: this caused issues, do we need it?
// indexRequest.version(RestActions.parseVersion(request));
// indexRequest.versionType(VersionType.fromString(request.param("version_type"),
// indexRequest.versionType()));
indexRequest.percolate(request.param("percolate", null));
indexRequest.opType(IndexRequest.OpType.INDEX);
// TODO: force creation of index, do we need it?
// indexRequest.create(true);
String replicationType = request.param("replication");
if (replicationType != null) {
indexRequest.replicationType(ReplicationType.fromString(replicationType));
}
String consistencyLevel = request.param("consistency");
if (consistencyLevel != null) {
indexRequest.consistencyLevel(WriteConsistencyLevel.fromString(consistencyLevel));
}
// we just send a response, no need to fork
indexRequest.listenerThreaded(true);
// we don't spawn, then fork if local
indexRequest.operationThreaded(true);
return indexRequest;
}