Getting UUID from Apache Solr after commit

I use Solrj to add new documents to a Solr instance. In my document schema, the identifier is UUID ( solr.UUIDField). Each time a document is created, the identifier is populated with a unique identifier, which is exactly what I want. Sometimes in my application it is necessary for me to be able to get this unique identifier in order to add it as a field value when inserting another document. So my question is: how can I get this generated uuid from solr after adding a document?

Solrj returns this UpdateResponse object to me after committing, but I do not know how to extract a new uuid from it.

I am adding a document like this

CommonsHttpSolrServer server = new CommonsHttpSolrServer(MY_SERVER_URL);

SolrInputDocument doc = new SolrInputDocument();
// [...] multiple addField calls
server.add(doc);
UpdateResponse ur = server.commit();
+3
1

AFAIK UUID . , , ( , ). , HTTP, / :

http://localhost:8983/solr/update?stream.body=<add><doc><field name="id">test</field><field name="title">test title</field></doc></add>
http://localhost:8983/solr/update?stream.body=<commit/>

-, , . , SolrJ ( ).

() Java, . "timestamp" Solr, solr , .

, . , Solr, . UUID " ". , UUID.

Java, UUID, :

CommonsHttpSolrServer server = new CommonsHttpSolrServer(MY_SERVER_URL);

SolrInputDocument doc = new SolrInputDocument();
UUID uuid = UUID.randomUUID();
doc.addField("id", uuid.toString());
// [...] multiple addField calls
server.add(doc);
UpdateResponse ur = server.commit();
+4

All Articles