Skip to content

Commit

Permalink
fixed version conflict exception caused by the use of create() instea…
Browse files Browse the repository at this point in the history
…d of update()
  • Loading branch information
albogdano committed Apr 29, 2022
1 parent afba9f2 commit d2713a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/erudika/para/server/search/es/ES.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public static <P extends ParaObject> void indexAllInternal(String appid, List<P>
try {
executeRequests(objects.stream().
filter(Objects::nonNull).
map(obj -> BulkOperation.of(b -> b.create(d -> d.index(getIndexName(appid)).id(obj.getId()).
document(ESUtils.getSourceFromParaObject(obj))))).
map(obj -> BulkOperation.of(b -> b.update(d -> d.index(getIndexName(appid)).id(obj.getId()).
action(a -> a.doc(ESUtils.getSourceFromParaObject(obj)).docAsUpsert(true))))).
collect(Collectors.toList()));
logger.debug("Search.indexAll() {}", objects.size());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,22 @@ public void testNestedMapping() {
p = ESUtils.getDefaultMapping().get("properties");
assertTrue(p != null && p.object().enabled());
}

@Test
public void testVersionConflict() {
Sysprop t1 = new Sysprop("vc1");
t1.setType("test");
t1.setAppid(appid1);
t1.setTimestamp(System.currentTimeMillis());
t1.setName("v1");
s.index(t1.getAppid(), t1);
assertEquals("v1", s.findById(appid1, t1.getId()).getName());
t1.setName("v2");
s.index(t1.getAppid(), t1);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) { }
assertEquals("v2", s.findById(appid1, t1.getId()).getName());
s.unindex(t1);
}
}

0 comments on commit d2713a5

Please sign in to comment.