Questions Tagged With elasticsearchhttps://answers.axonivy.com/tags/elasticsearch/?type=rss&user=vagabondquestions tagged <span class="tag">elasticsearch</span>enFri, 22 Feb 2019 01:16:25 -0500There is a 1-second latency between ivy.repo.save(object) and ivy.repo.search(Object.class)https://answers.axonivy.com/questions/3681/there-is-a-1-second-latency-between-ivy-repo-save-object-and-ivy-repo-search-object-class<p>Hi Axon.ivy Team,</p> <p>Given the snippet of code:</p> <pre><code>Person p = new Person(); p.id = UUID.randomUUID().toString(); p.name = "John Doe"; p.birthdate = LocalDate.now(); ivy.repo.save(p); Object result = ivy.repo.search(Person.class) .textField("id").containsPhrase(p.id) .execute().getFirst(); ivy.log.error("HHH - it is null " + #result); Thread.sleep(TimeUnit.SECONDS.toMillis(1)); result = ivy.repo.search(Person.class) .textField("id").containsPhrase(p.id) .execute().getFirst(); ivy.log.error("HHH - it is null " + #result); </code></pre> <p>I found that there was a <em>1-second</em> latency between the call to <code>ivy.repo.save()</code> and <code>ivy.repo.search()</code>. This is super annoying because we had to wait for <em>1-second</em> every time until the saved object can be searched via the API. Blocking the execution for 1-second to wait until it is indexed to ES <em>every</em> <em>time</em> we save the object into the <code>BusinessDataRepository</code> is a terrible hack.</p> <p>Is it by design? Can this be fixed so that the two calls work?</p> <blockquote> <p>P.S: Please don't advise me to use the returned BusinessData id because it doesn't address my issue. I want to <em>search</em> back the data I save based on the object's field, not fetching it again.</p> <p>P.P.S: Tested with Axon.ivy Designer 7.2.1 on my local workstation.</p> </blockquote> <p><strong>UPDATE</strong></p> <p><em>25.2.2019</em>:</p> <p>In our project, we were able to develop RESTful API for other parties. As we already have persisted our objects (for example <code>Dossier</code>), in <code>BusinessDataRespository</code>, we would want to preserve that behavior.</p> <p>An excerpt from of our OpenAPI spec:</p> <pre><code>paths: /dossiers/{dossier_id}/persons/: post: operationId: addPersonToDossier description: add a single person into an existing Dossier requestbody: 'application/json': schema: $ref: '#/components/schemas/Person' responses: '201': get: operationId: getAllPersonsInDossier description: get *all* existing persons of an existing Dossier responses: '200': content: 'application/json': schema: type: array items: $ref: '#/components/schemas/Person' </code></pre> <p>From our client, after they have already invoked several calls to <code>addPersonToDossier</code>, they may want to invoke <code>getAllPersonsInDossier</code> to fetch all <code>Person</code>s of a <code>Dossier</code>. </p> <p>We persists <code>Person</code> separately from our <code>Dossier</code> to avoid <code>ConcurrentModificationException</code>, each <code>Person</code> holds a reference to its <code>Dossier</code>. Now in order to implement <code>getAllPersonsInDossier</code>, we have to use <code>Ivy.repo().search(..)</code>.</p> <p>Unfortunately, due to the 1-second latency, calling <code>getAllPersonsInDossier</code> too soon will probably return an empty result. This forces us to either:</p> <ul> <li>Require our clients to WAIT on their side for <em>1-second</em> until they can call <code>getAllPersonsInDossier</code>.</li> <li>On the server side, we somehow have to implement a <code>while</code> loop to check until the <code>Person</code> could be found via search API, then we consider the <code>addPersonToDossier</code> finishes (or worse, a <code>Thread.sleep(1000)</code>).</li> </ul> <p>Jack</p>vagabondFri, 22 Feb 2019 01:16:25 -0500https://answers.axonivy.com/questions/3681/there-is-a-1-second-latency-between-ivy-repo-save-object-and-ivy-repo-search-object-classbusiness-dataelasticsearchrepository