@@ -78,6 +78,16 @@ public Object put(String key, Object value) {
78
78
private String type ;
79
79
private String index ;
80
80
81
+ /**
82
+ * As an id is not required it can be omitted.
83
+ *
84
+ * @param type The Elasticsearch index type
85
+ * @param index The Elasticsearch index name
86
+ */
87
+ public JsonToElasticsearchBulk (String type , String index ) {
88
+ this (new String [] { }, type , index );
89
+ }
90
+
81
91
/**
82
92
* @param idPath The key path of the JSON value to be used as the ID for the record
83
93
* @param type The Elasticsearch index type
@@ -116,7 +126,7 @@ public void process(String obj) {
116
126
Map <String , Object > detailsMap = new HashMap <String , Object >();
117
127
Map <String , Object > indexMap = new HashMap <String , Object >();
118
128
indexMap .put ("index" , detailsMap );
119
- detailsMap .put ("_id" , findId (json ));
129
+ if ( idPath . length > 0 ) detailsMap .put ("_id" , findId (json ));
120
130
detailsMap .put ("_type" , type );
121
131
detailsMap .put ("_index" , index );
122
132
mapper .writeValue (stringWriter , indexMap );
@@ -129,10 +139,6 @@ public void process(String obj) {
129
139
}
130
140
131
141
private Object findId (Object value ) {
132
- if (idPath .length < 1 ) {
133
- return null ;
134
- }
135
-
136
142
for (final String key : idPath ) {
137
143
if (value instanceof Map ) {
138
144
@ SuppressWarnings ("unchecked" )
0 commit comments