You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-11Lines changed: 36 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ The library reads all the metadata it needs from the entity classes (index name,
14
14
* Support for **JUnit 4** via `LoadEsDataRule`, `DeleteEsDataRule`
15
15
* Support for **JUnit Jupiter** via `@LoadEsDataConfig` / `@LoadEsDataExtension` or `@DeleteEsDataConfig` / `@DeleteEsDataExtension`
16
16
* Built-in support for **gzipped data**
17
+
* Multiple data formats(dump, manual)
17
18
* Written in **Java 8**
18
19
* Based on **Spring (Data, Test)**
19
20
@@ -26,7 +27,7 @@ The library reads all the metadata it needs from the entity classes (index name,
26
27
27
28
## Installation & Usage
28
29
29
-
The library is splitted into 2 independent sub-modules, both are available on [JCenter](https://bintray.com/bintray/jcenter?filterByPkgName=spring-esdata-loader) and [Maven Central](https://search.maven.org/search?q=spring-esdata-loader):
30
+
The library is split into 2 independent sub-modules, both are available on [JCenter](https://bintray.com/bintray/jcenter?filterByPkgName=spring-esdata-loader) and [Maven Central](https://search.maven.org/search?q=spring-esdata-loader):
30
31
31
32
*`spring-esdata-loader-junit4` for testing with **JUnit 4**
32
33
*`spring-esdata-loader-junit-jupiter` for testing with **JUnit Jupiter**
@@ -80,25 +81,28 @@ To get started,
80
81
*[junit4](/junit4) - if your are using **JUnit 4**
81
82
*[junit-jupiter](/junit-jupiter) - if you are using **JUnit Jupiter**
82
83
83
-
## Data Format
84
+
## Supported Data Formats
85
+
86
+
`spring-esdata-loader` currently supports 2 formats to load data into Elasticsearch: **DUMP** and **MANUAL**.
87
+
88
+
### Dump data format
84
89
85
-
The data to be loaded must follow the appropriate format.
> If you change the `--output` part above into `--output=$ | gzip my_data.json.gz` the data will be automatically gzipped
110
114
115
+
### Manual data format
116
+
117
+
In this format, you specify your target data directly (no metadata like `_index`, `_source`, ...), as an Array of JSON objects.
118
+
119
+
This is more suitable when you create test data from scratch (as opposed to dumping existing ones from a ES server) because it is easier to tweak later on to accommodate future modifications in tests. _(Thanks to @DPorcheron for the idea 💡!)_
Copy file name to clipboardExpand all lines: core/src/main/java/com/github/spring/esdata/loader/core/IndexData.java
+91-82Lines changed: 91 additions & 82 deletions
Original file line number
Diff line number
Diff line change
@@ -6,102 +6,111 @@
6
6
* Data is basically represented by:
7
7
* <ul>
8
8
* <li><code>esEntityClass</code>: mapping class, used to create the corresponding index and mapping</li>
9
-
* <li><code>location</code>: path to the JSON file that contains the actual data to import</li>
9
+
* <li><code>location</code>: path to the JSON file that contains the actual data to import (can be gzipped)</li>
10
10
* <li><code>nbMaxItems</code> (<i>optional</i>): how many max items to load (<code>all</code> <i>by default</i> )</li>
11
11
* <li><code>nbSkipItems</code> (<i>optional</i>): how many items to skip (<code>0</code> <i>by default</i> )</li>
12
+
* <li><code>format</code> (<i>optional</i>): format of the data to import (<code>null</code> <i>by default</i>, will be detected from JSON file content )</li>
12
13
* </ul>
13
14
*
14
15
* @author tinesoft
15
-
*
16
16
*/
17
17
publicclassIndexData {
18
18
19
-
finalClass<?> esEntityClass;
20
-
finalStringlocation;
21
-
finalbooleangzipped;
22
-
finalLongnbMaxItems;
23
-
finalLongnbSkipItems;
19
+
finalClass<?> esEntityClass;
20
+
finalStringlocation;
21
+
finalbooleangzipped;
22
+
finalLongnbMaxItems;
23
+
finalLongnbSkipItems;
24
+
finalEsDataFormatformat;
25
+
26
+
/**
27
+
* @param esEntityClass mapping class of the data to be indexed in ES
28
+
* @param location path to the file that contains data (as JSON) to be indexed
29
+
* @param gzipped whether or not the data is gzipped (true by default)
30
+
* @param nbMaxItems maximum number of items to load
0 commit comments