<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: There is a 1-second latency between ivy.repo.save(object) and ivy.repo.search(Object.class)</title><link>https://answers.axonivy.com/questions/3681/there-is-a-1-second-latency-between-ivy-repo-save-object-and-ivy-repo-search-object-class</link><description>&lt;p&gt;Hi Axon.ivy Team,&lt;/p&gt;
&lt;p&gt;Given the snippet of code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;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);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I found that there was a &lt;em&gt;1-second&lt;/em&gt; latency between the call to &lt;code&gt;ivy.repo.save()&lt;/code&gt; and &lt;code&gt;ivy.repo.search()&lt;/code&gt;. This is super annoying because we had to wait for &lt;em&gt;1-second&lt;/em&gt; 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 &lt;em&gt;every&lt;/em&gt; &lt;em&gt;time&lt;/em&gt; we save the object into the &lt;code&gt;BusinessDataRepository&lt;/code&gt; is a terrible hack.&lt;/p&gt;
&lt;p&gt;Is it by design? Can this be fixed so that the two calls work?&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;P.S: Please don't advise me to use the returned BusinessData id because it doesn't address my issue. I want to &lt;em&gt;search&lt;/em&gt; back the data I save based on the object's field, not fetching it again.&lt;/p&gt;
&lt;p&gt;P.P.S: Tested with Axon.ivy Designer 7.2.1 on my local workstation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;25.2.2019&lt;/em&gt;:&lt;/p&gt;
&lt;p&gt;In our project, we were able to develop RESTful API for other parties. As we already have persisted our objects (for example &lt;code&gt;Dossier&lt;/code&gt;), in &lt;code&gt;BusinessDataRespository&lt;/code&gt;, we would want to preserve that behavior.&lt;/p&gt;
&lt;p&gt;An excerpt from of our OpenAPI spec:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;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'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From our client, after they have already invoked several calls to &lt;code&gt;addPersonToDossier&lt;/code&gt;, they may want to invoke &lt;code&gt;getAllPersonsInDossier&lt;/code&gt; to fetch all &lt;code&gt;Person&lt;/code&gt;s of a &lt;code&gt;Dossier&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;We persists &lt;code&gt;Person&lt;/code&gt; separately from our &lt;code&gt;Dossier&lt;/code&gt; to avoid  &lt;code&gt;ConcurrentModificationException&lt;/code&gt;, each &lt;code&gt;Person&lt;/code&gt; holds a reference to its &lt;code&gt;Dossier&lt;/code&gt;. Now in order to implement &lt;code&gt;getAllPersonsInDossier&lt;/code&gt;, we have to use &lt;code&gt;Ivy.repo().search(..)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Unfortunately, due to the 1-second latency, calling &lt;code&gt;getAllPersonsInDossier&lt;/code&gt; too soon will probably return an empty result. This forces us to either:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Require our clients to WAIT on their side for &lt;em&gt;1-second&lt;/em&gt; until they can call &lt;code&gt;getAllPersonsInDossier&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;On the server side, we somehow have to implement a &lt;code&gt;while&lt;/code&gt; loop to check until the &lt;code&gt;Person&lt;/code&gt; could be found via search API, then we consider the &lt;code&gt;addPersonToDossier&lt;/code&gt; finishes (or worse, a &lt;code&gt;Thread.sleep(1000)&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Jack&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/3681/there-is-a-1-second-latency-between-ivy-repo-save-object-and-ivy-repo-search-object-class" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 27 Feb 2019 08:21:34 -0500</lastBuildDate><item><title>Answer by Alex Suter</title><link>https://answers.axonivy.com/questions/3681/there-is-a-1-second-latency-between-ivy-repo-save-object-and-ivy-repo-search-object-class/3714</link><description>&lt;p&gt;Hello &lt;a href="https://answers.axonivy.com/users/1130/vagabond"&gt;&lt;a href="https://answers.axonivy.com/users/1130/vagabond"&gt;@vagabond&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is Elasticsarch. It depends on the refresh interval:
&lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-indexing-speed.html"&gt;https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-indexing-speed.html&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alex Suter</dc:creator><pubDate>Wed, 27 Feb 2019 08:21:34 -0500</pubDate><guid>https://answers.axonivy.com/questions/3681/there-is-a-1-second-latency-between-ivy-repo-save-object-and-ivy-repo-search-object-class/3714</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/3681/there-is-a-1-second-latency-between-ivy-repo-save-object-and-ivy-repo-search-object-class/3686</link><description>&lt;p&gt;It is by design that we rely on ElasticSearch to deliver search results. And yes we accept the fact that search results can be not 100% sync for some millis. On the other hand queries execute blazing fast (even one tremendous data sets) and allow very powerful google like search terms.&lt;/p&gt;
&lt;p&gt;If you need a rock hard, 100% sync at anytime, persistency solution - BusinessData is maybe not the feature you are looking for. Just use JPA (ivy EntityClass) or any other persistency technology you like that relies on classical (often slow and inconvenient) relational database schemas.&lt;/p&gt;
&lt;p&gt;And of course you already mentioned it by yourself. Our BusinessData set is always consistenly saved. And therefore you have access to them e.g. by Id. But search features could take some millies to deliver accurate results.&lt;/p&gt;
&lt;p&gt;I think it is very unlikely that one would favor a 100% up to date search result over the benefits of a powerful query engine. Unless you are implementing a stock broker service. But maybe you can share your use-case....&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 22 Feb 2019 10:01:57 -0500</pubDate><guid>https://answers.axonivy.com/questions/3681/there-is-a-1-second-latency-between-ivy-repo-save-object-and-ivy-repo-search-object-class/3686</guid></item></channel></rss>