Saving a DataFrame to Couchbase


I am trying to save a Spark DataFrame (extracted from ElasticSearch) following the documentation here:

It looks like I have to explicitly specify a column in the DataFrame that will be used as the ID field, but the data I have is unstructured and different documents have different fields… so for unstructured data, how can I decide which field to use as the document ID? Is it possible to have Couchbase generate the ID automatically?


You can use uuid function/class to generate random unique number. example below-

n1ql query-
insert into mybucket values (uuid(),{“name”: “John”,“age”:30});

From spark-
JsonDocument.create(UUID.randomUUID().toString(), content)