Skip to content

Commit 1cbf8f9

Browse files
authored
Merge pull request #86 from octaavio/master
Feature to specify ES pipeline for a given spreadsheet
2 parents 574b361 + 8da7845 commit 1cbf8f9

File tree

7 files changed

+40
-11
lines changed

7 files changed

+40
-11
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Parses XLSX/XLS/CSV files into ElasticSearch using column titles from a specifie
1313
- support for importing to TLS enabled elasticsearch servers.
1414
- supports concurrent parsing of excel files and importing for better performance.
1515
- parses the whole file before starting the import - to make sure your index is not left in an undesired state.
16+
- specify elasticsearch ingest pipeline for a given spreadsheet.
1617

1718
## Prerequisites
1819
The application requires ElasticSearch as its output.
@@ -21,7 +22,7 @@ The application requires ElasticSearch as its output.
2122

2223
2. Grab the latest .jar file from [releases](https://github.com/codingchili/parser-excel-elasticsearch/releases).
2324

24-
Tested with ElasticSearch 5.6.2, 6.4.2 and 7.0.0-alpha1
25+
Tested with ElasticSearch 5.6.2, 6.4.2, 7.0.0-alpha1 and 7.4.0.
2526

2627
## Running with docker
2728
```console
@@ -35,7 +36,7 @@ connect to it from another machine when binding to all interfaces.
3536

3637
Running the application, filename and index is required, to import from the terminal run:
3738
```console
38-
java -Xmx2g -jar excelastic.jar <fileName> <indexName> --mapping mappingName --clear
39+
java -Xmx2g -jar excelastic.jar <fileName> <indexName> --mapping mappingName --pipeline pipelineName --clear
3940
```
4041
If running with --clear, then the existing index will be cleared before the import starts.
4142

excelastic.png

257 KB
Loading

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<groupId>com.codingchili</groupId>
1212
<artifactId>excelastic</artifactId>
13-
<version>1.3.6</version>
13+
<version>1.3.7</version>
1414
<build>
1515
<plugins>
1616
<plugin>

src/main/java/com/codingchili/ApplicationLauncher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public class ApplicationLauncher {
2323
private final ApplicationLogger logger = new ApplicationLogger(getClass());
24-
public static String VERSION = "1.3.6";
24+
public static String VERSION = "1.3.7";
2525
private Vertx vertx;
2626

2727
public static void main(String[] args) {

src/main/java/com/codingchili/Model/ElasticWriter.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,18 @@ private void updateStatus(HttpClientResponse response, ImportEvent event, int re
158158
}
159159

160160
private String createImportHeader(ImportEvent event) {
161+
JsonObject indexBody = new JsonObject();
162+
indexBody.put("_index", event.getIndex())
163+
.put("_type", event.getMapping());
164+
165+
event.getPipeline()
166+
.filter(value -> !value.isEmpty())
167+
.ifPresent((pipeline) -> indexBody.put("pipeline", pipeline));
168+
161169
return new JsonObject()
162-
.put("index", new JsonObject()
163-
.put("_index", event.getIndex())
164-
.put("_type", event.getMapping())).encode() + "\n";
170+
.put("index", indexBody)
171+
.encode() + "\n";
172+
165173
}
166174

167175
/**

src/main/java/com/codingchili/Model/ImportEvent.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@
1111
/**
1212
* @author Robin Duda
1313
* <p>
14-
* Contains infromation about an import request.
14+
* Contains information about an import request.
1515
*/
1616
public class ImportEvent {
1717
private static final String ARG_CLEAR = "--clear";
1818
private static final String ARG_OFFSET = "--offset";
1919
private static final String ARG_MAPPING = "--mapping";
20+
private static final String ARG_PIPELINE = "--pipeline";
2021
private static final String OFFSET = "offset";
2122
private static final String MAPPING = "mapping";
23+
private static final String PIPELINE = "pipeline";
2224
private static final String OPTIONS = "options";
2325
private static final String CLEAR = "clear";
2426
private FileParser parser;
2527
private Boolean clearExisting;
2628
private String mapping;
29+
private Optional<String> pipeline;
2730
private String index;
2831
private String uploadId;
2932
private int offset;
@@ -38,6 +41,7 @@ public static ImportEvent fromParams(MultiMap params) {
3841
return new ImportEvent()
3942
.setIndex(params.get(INDEX))
4043
.setMapping(getMappingByParams(params))
44+
.setPipeline(params.get(PIPELINE))
4145
.setClearExisting(params.get(OPTIONS).equals(CLEAR))
4246
.setUploadId(params.get(UPLOAD_ID))
4347
.setOffset(Integer.parseInt(params.get(OFFSET)));
@@ -53,15 +57,17 @@ public static ImportEvent fromCommandLineArgs(String[] args) {
5357
return new ImportEvent()
5458
.setIndex(args[1])
5559
.setOffset(getArgParamValue(args, ARG_OFFSET).map(Integer::parseInt).orElse(1))
56-
.setClearExisting(Arrays.asList(args).contains(ARG_CLEAR))
57-
.setMapping(getArgParamValue(args, ARG_MAPPING).orElse("default"));
60+
.setMapping(getArgParamValue(args, ARG_MAPPING).orElse("default"))
61+
.setPipeline(getArgParamValue(args, ARG_PIPELINE).orElse(""))
62+
.setClearExisting(Arrays.asList(args).contains(ARG_CLEAR));
63+
5864
}
5965

6066
private static Optional<String> getArgParamValue(String[] args, String argName) {
6167
for (int i = 0; i < args.length; i++) {
6268
if (args[i].equals(argName)) {
6369
if (i + 1 < args.length) {
64-
return Optional.of(args[i + i]);
70+
return Optional.of(args[i + 1]);
6571
}
6672
}
6773
}
@@ -132,4 +138,14 @@ public ImportEvent setIndex(String index) {
132138
this.index = index;
133139
return this;
134140
}
141+
142+
public Optional<String> getPipeline() {
143+
return pipeline;
144+
}
145+
146+
public ImportEvent setPipeline(String pipeline) {
147+
this.pipeline = Optional.ofNullable(pipeline);
148+
return this;
149+
}
150+
135151
}

src/main/resources/templates/index.jade

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ html(lang='en')
3232
label.col-lg-3.control-label(for='mapping') Mapping
3333
.col-lg-9
3434
input#index.form-control(type='text', name='mapping', placeholder='default')
35+
.form-group
36+
label.col-lg-3.control-label(for='pipeline') Pipeline
37+
.col-lg-9
38+
input#index.form-control(type='text', name='pipeline', placeholder='none if empty')
3539
a.text-center.clickable#excel-options-show
3640
show excel options
3741
.form-group(hidden)#excel-options

0 commit comments

Comments
 (0)