Skip to content

Commit 7fb1f47

Browse files
committed
+feature: Create a new collection from JSON file
1 parent 66f3753 commit 7fb1f47

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ collectionSchema.name("Countries").fields(fields).defaultSortingField("gdp");
5757
client.collections().create(collectionSchema);
5858
```
5959

60+
### Create a new collection from JSON file
61+
```java
62+
String schemaJson = new String(
63+
Files.readAllBytes(Paths.get("schema.json")),
64+
StandardCharsets.UTF_8
65+
);
66+
client.collections().create(schemaJson);
67+
```
68+
6069
### Index a document
6170
```java
6271
Map<String, Object> hmap = new HashMap<>();

src/main/java/org/typesense/api/Collections.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public CollectionResponse create(CollectionSchema c) throws Exception {
1616
return this.apiCall.post(RESOURCE_PATH, c, null, CollectionResponse.class);
1717
}
1818

19+
public CollectionResponse create(String schemaJson) throws Exception {
20+
return this.apiCall.post(RESOURCE_PATH, schemaJson, null, CollectionResponse.class);
21+
}
22+
1923
public CollectionResponse[] retrieve() throws Exception {
2024
return this.apiCall.get(RESOURCE_PATH, null, CollectionResponse[].class);
2125
}

0 commit comments

Comments
 (0)