@@ -45,7 +45,7 @@ public final class JsonToElasticsearchBulkTest {
45
45
private static final String TYPE1 = "T1" ;
46
46
private static final String INDEX1 = "I1" ;
47
47
48
- private static final String METADATA = "{'index':{'_index':'I1','_type':'T1','_id': %s}}" ;
48
+ private static final String METADATA = "{'index':{'_index':'I1','_type':'T1'%s}}" ;
49
49
50
50
private static final String ENTITY_SEPARATOR1 = "." ;
51
51
private static final String ENTITY_SEPARATOR2 = ":" ;
@@ -122,7 +122,13 @@ public void testShouldNotExtractEmptyIdKey() {
122
122
@ Test
123
123
public void testShouldNotExtractEmptyIdPath () {
124
124
setBulk (new String [0 ]);
125
- shouldNotExtractId ("{'L1':'V1','L2':'V2','L3':'V3'}" );
125
+ shouldExtractId ("{'L1':'V1','L2':'V2','L3':'V3'}" , null );
126
+ }
127
+
128
+ @ Test
129
+ public void testShouldNotExtractOmittedIdPath () {
130
+ bulk = new JsonToElasticsearchBulk (TYPE1 , INDEX1 );
131
+ shouldExtractId ("{'L1':'V1','L2':'V2','L3':'V3'}" , null );
126
132
}
127
133
128
134
@ Test
@@ -220,7 +226,9 @@ private void shouldExtractId(final String obj, final String idValue, final Strin
220
226
bulk .setReceiver (receiver );
221
227
bulk .process (fixQuotes (obj ));
222
228
223
- verify (receiver ).process (fixQuotes (String .format (METADATA , idValue ) + "\n " + resultObj ));
229
+ final String metadata = String .format (METADATA , idValue != null ? ",'_id':" + idValue : "" );
230
+
231
+ verify (receiver ).process (fixQuotes (metadata + "\n " + resultObj ));
224
232
verifyNoMoreInteractions (receiver );
225
233
}
226
234
0 commit comments