Populate changes directly to elastic search












0














I'm writing a small demo application and used jHipster to generate the stack. As i'm quite new to web development I ran into some issues, especially with elastic search.



Whenever I change entity data in my application, the changed data is not reflected in searches executed using elastic search.



My understanding was that if entity changes were saved in the respective search repository, it should be reflected in the ES indices. Am I mistaken about that?



A live example:



@Override
public Client save(Client client) {
log.debug("Request to save Client : {}", client);
Client result = clientRepository.save(client);
clientSearchRepository.save(result);
return result;
}


This stored updated information in my MySQL database, so far so good. However, let's say i edited the birth date of the user and saved it. Whenever I search something containing that client, the "old" birth date still shows up until I perform a reindexation of the ES repositories.



Is it possible to use some kind of entity listener (or anything else) that populates the changed data directly?



Thanks for any pointers.










share|improve this question



























    0














    I'm writing a small demo application and used jHipster to generate the stack. As i'm quite new to web development I ran into some issues, especially with elastic search.



    Whenever I change entity data in my application, the changed data is not reflected in searches executed using elastic search.



    My understanding was that if entity changes were saved in the respective search repository, it should be reflected in the ES indices. Am I mistaken about that?



    A live example:



    @Override
    public Client save(Client client) {
    log.debug("Request to save Client : {}", client);
    Client result = clientRepository.save(client);
    clientSearchRepository.save(result);
    return result;
    }


    This stored updated information in my MySQL database, so far so good. However, let's say i edited the birth date of the user and saved it. Whenever I search something containing that client, the "old" birth date still shows up until I perform a reindexation of the ES repositories.



    Is it possible to use some kind of entity listener (or anything else) that populates the changed data directly?



    Thanks for any pointers.










    share|improve this question

























      0












      0








      0







      I'm writing a small demo application and used jHipster to generate the stack. As i'm quite new to web development I ran into some issues, especially with elastic search.



      Whenever I change entity data in my application, the changed data is not reflected in searches executed using elastic search.



      My understanding was that if entity changes were saved in the respective search repository, it should be reflected in the ES indices. Am I mistaken about that?



      A live example:



      @Override
      public Client save(Client client) {
      log.debug("Request to save Client : {}", client);
      Client result = clientRepository.save(client);
      clientSearchRepository.save(result);
      return result;
      }


      This stored updated information in my MySQL database, so far so good. However, let's say i edited the birth date of the user and saved it. Whenever I search something containing that client, the "old" birth date still shows up until I perform a reindexation of the ES repositories.



      Is it possible to use some kind of entity listener (or anything else) that populates the changed data directly?



      Thanks for any pointers.










      share|improve this question













      I'm writing a small demo application and used jHipster to generate the stack. As i'm quite new to web development I ran into some issues, especially with elastic search.



      Whenever I change entity data in my application, the changed data is not reflected in searches executed using elastic search.



      My understanding was that if entity changes were saved in the respective search repository, it should be reflected in the ES indices. Am I mistaken about that?



      A live example:



      @Override
      public Client save(Client client) {
      log.debug("Request to save Client : {}", client);
      Client result = clientRepository.save(client);
      clientSearchRepository.save(result);
      return result;
      }


      This stored updated information in my MySQL database, so far so good. However, let's say i edited the birth date of the user and saved it. Whenever I search something containing that client, the "old" birth date still shows up until I perform a reindexation of the ES repositories.



      Is it possible to use some kind of entity listener (or anything else) that populates the changed data directly?



      Thanks for any pointers.







      java elasticsearch jhipster






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 22:39









      Fish-GutsFish-Guts

      1039




      1039
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You should use same searchrepository on your update method. Your code above looks good, if your ElasticSearch config is correct it should update index on create/update of entity.



          Use JHipster entity generator and enable elasticsearch and it should work out of the box.



          You'll get something like this in your ClientResource for creating new clients:



          @PostMapping("/clients")
          @Timed
          public ResponseEntity<Client> createClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          And something like this for editing your clients:



              @PutMapping("/clients")
          @Timed
          public ResponseEntity<Client> updateClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          Try generating new empty JHipster project and include ElasticSearch ad you'll see that it works like you suppose in the first place.






          share|improve this answer





















          • Thanks for your reply. This is exactly what I would expect it to look like, and jHipster calls the repository directly. However, whenever I change some data for e.g Client, the changed information will now show up in search results unless I perform an ES reindexation.
            – Fish-Guts
            Dec 5 '18 at 7:32










          • What part of Client data are you changing. If you are changing data in DB directly ES is not aware of that change and sure, you'll need to reindex it. Change on data need to be propagated through your app, first to DB and then to ES like JHipster generated app does it. In every way, you can schedule the ES reindexing if you are not allowed to modify all applications that write to your DB and can't be modified to call ES.
            – D00de
            Dec 8 '18 at 20:34










          • I'm changing it through the application, not on the DB directly. This is why I don't understand why populating is not working. My understanding was that the call to clientSearchRepository.save(result); should take care of that.
            – Fish-Guts
            Dec 9 '18 at 20:01










          • Yes, that's exactly it. That's why I said to try and generate new application and see that it works that way. clientSearchRepository extends ElasticsearchRepository, and it's mission is to keep ElasticSearch index in line with database changes. Therefor you have clientSearchRepository methods right after clientRepository in any create/update function of your backend app.
            – D00de
            Dec 10 '18 at 9:46











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453585%2fpopulate-changes-directly-to-elastic-search%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You should use same searchrepository on your update method. Your code above looks good, if your ElasticSearch config is correct it should update index on create/update of entity.



          Use JHipster entity generator and enable elasticsearch and it should work out of the box.



          You'll get something like this in your ClientResource for creating new clients:



          @PostMapping("/clients")
          @Timed
          public ResponseEntity<Client> createClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          And something like this for editing your clients:



              @PutMapping("/clients")
          @Timed
          public ResponseEntity<Client> updateClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          Try generating new empty JHipster project and include ElasticSearch ad you'll see that it works like you suppose in the first place.






          share|improve this answer





















          • Thanks for your reply. This is exactly what I would expect it to look like, and jHipster calls the repository directly. However, whenever I change some data for e.g Client, the changed information will now show up in search results unless I perform an ES reindexation.
            – Fish-Guts
            Dec 5 '18 at 7:32










          • What part of Client data are you changing. If you are changing data in DB directly ES is not aware of that change and sure, you'll need to reindex it. Change on data need to be propagated through your app, first to DB and then to ES like JHipster generated app does it. In every way, you can schedule the ES reindexing if you are not allowed to modify all applications that write to your DB and can't be modified to call ES.
            – D00de
            Dec 8 '18 at 20:34










          • I'm changing it through the application, not on the DB directly. This is why I don't understand why populating is not working. My understanding was that the call to clientSearchRepository.save(result); should take care of that.
            – Fish-Guts
            Dec 9 '18 at 20:01










          • Yes, that's exactly it. That's why I said to try and generate new application and see that it works that way. clientSearchRepository extends ElasticsearchRepository, and it's mission is to keep ElasticSearch index in line with database changes. Therefor you have clientSearchRepository methods right after clientRepository in any create/update function of your backend app.
            – D00de
            Dec 10 '18 at 9:46
















          0














          You should use same searchrepository on your update method. Your code above looks good, if your ElasticSearch config is correct it should update index on create/update of entity.



          Use JHipster entity generator and enable elasticsearch and it should work out of the box.



          You'll get something like this in your ClientResource for creating new clients:



          @PostMapping("/clients")
          @Timed
          public ResponseEntity<Client> createClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          And something like this for editing your clients:



              @PutMapping("/clients")
          @Timed
          public ResponseEntity<Client> updateClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          Try generating new empty JHipster project and include ElasticSearch ad you'll see that it works like you suppose in the first place.






          share|improve this answer





















          • Thanks for your reply. This is exactly what I would expect it to look like, and jHipster calls the repository directly. However, whenever I change some data for e.g Client, the changed information will now show up in search results unless I perform an ES reindexation.
            – Fish-Guts
            Dec 5 '18 at 7:32










          • What part of Client data are you changing. If you are changing data in DB directly ES is not aware of that change and sure, you'll need to reindex it. Change on data need to be propagated through your app, first to DB and then to ES like JHipster generated app does it. In every way, you can schedule the ES reindexing if you are not allowed to modify all applications that write to your DB and can't be modified to call ES.
            – D00de
            Dec 8 '18 at 20:34










          • I'm changing it through the application, not on the DB directly. This is why I don't understand why populating is not working. My understanding was that the call to clientSearchRepository.save(result); should take care of that.
            – Fish-Guts
            Dec 9 '18 at 20:01










          • Yes, that's exactly it. That's why I said to try and generate new application and see that it works that way. clientSearchRepository extends ElasticsearchRepository, and it's mission is to keep ElasticSearch index in line with database changes. Therefor you have clientSearchRepository methods right after clientRepository in any create/update function of your backend app.
            – D00de
            Dec 10 '18 at 9:46














          0












          0








          0






          You should use same searchrepository on your update method. Your code above looks good, if your ElasticSearch config is correct it should update index on create/update of entity.



          Use JHipster entity generator and enable elasticsearch and it should work out of the box.



          You'll get something like this in your ClientResource for creating new clients:



          @PostMapping("/clients")
          @Timed
          public ResponseEntity<Client> createClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          And something like this for editing your clients:



              @PutMapping("/clients")
          @Timed
          public ResponseEntity<Client> updateClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          Try generating new empty JHipster project and include ElasticSearch ad you'll see that it works like you suppose in the first place.






          share|improve this answer












          You should use same searchrepository on your update method. Your code above looks good, if your ElasticSearch config is correct it should update index on create/update of entity.



          Use JHipster entity generator and enable elasticsearch and it should work out of the box.



          You'll get something like this in your ClientResource for creating new clients:



          @PostMapping("/clients")
          @Timed
          public ResponseEntity<Client> createClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          And something like this for editing your clients:



              @PutMapping("/clients")
          @Timed
          public ResponseEntity<Client> updateClient(@Valid @RequestBody Client client) throws URISyntaxException {

          Client result = clientRepository.save(client);
          clientSearchRepository.save(result);


          Try generating new empty JHipster project and include ElasticSearch ad you'll see that it works like you suppose in the first place.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 1 '18 at 16:22









          D00deD00de

          5212518




          5212518












          • Thanks for your reply. This is exactly what I would expect it to look like, and jHipster calls the repository directly. However, whenever I change some data for e.g Client, the changed information will now show up in search results unless I perform an ES reindexation.
            – Fish-Guts
            Dec 5 '18 at 7:32










          • What part of Client data are you changing. If you are changing data in DB directly ES is not aware of that change and sure, you'll need to reindex it. Change on data need to be propagated through your app, first to DB and then to ES like JHipster generated app does it. In every way, you can schedule the ES reindexing if you are not allowed to modify all applications that write to your DB and can't be modified to call ES.
            – D00de
            Dec 8 '18 at 20:34










          • I'm changing it through the application, not on the DB directly. This is why I don't understand why populating is not working. My understanding was that the call to clientSearchRepository.save(result); should take care of that.
            – Fish-Guts
            Dec 9 '18 at 20:01










          • Yes, that's exactly it. That's why I said to try and generate new application and see that it works that way. clientSearchRepository extends ElasticsearchRepository, and it's mission is to keep ElasticSearch index in line with database changes. Therefor you have clientSearchRepository methods right after clientRepository in any create/update function of your backend app.
            – D00de
            Dec 10 '18 at 9:46


















          • Thanks for your reply. This is exactly what I would expect it to look like, and jHipster calls the repository directly. However, whenever I change some data for e.g Client, the changed information will now show up in search results unless I perform an ES reindexation.
            – Fish-Guts
            Dec 5 '18 at 7:32










          • What part of Client data are you changing. If you are changing data in DB directly ES is not aware of that change and sure, you'll need to reindex it. Change on data need to be propagated through your app, first to DB and then to ES like JHipster generated app does it. In every way, you can schedule the ES reindexing if you are not allowed to modify all applications that write to your DB and can't be modified to call ES.
            – D00de
            Dec 8 '18 at 20:34










          • I'm changing it through the application, not on the DB directly. This is why I don't understand why populating is not working. My understanding was that the call to clientSearchRepository.save(result); should take care of that.
            – Fish-Guts
            Dec 9 '18 at 20:01










          • Yes, that's exactly it. That's why I said to try and generate new application and see that it works that way. clientSearchRepository extends ElasticsearchRepository, and it's mission is to keep ElasticSearch index in line with database changes. Therefor you have clientSearchRepository methods right after clientRepository in any create/update function of your backend app.
            – D00de
            Dec 10 '18 at 9:46
















          Thanks for your reply. This is exactly what I would expect it to look like, and jHipster calls the repository directly. However, whenever I change some data for e.g Client, the changed information will now show up in search results unless I perform an ES reindexation.
          – Fish-Guts
          Dec 5 '18 at 7:32




          Thanks for your reply. This is exactly what I would expect it to look like, and jHipster calls the repository directly. However, whenever I change some data for e.g Client, the changed information will now show up in search results unless I perform an ES reindexation.
          – Fish-Guts
          Dec 5 '18 at 7:32












          What part of Client data are you changing. If you are changing data in DB directly ES is not aware of that change and sure, you'll need to reindex it. Change on data need to be propagated through your app, first to DB and then to ES like JHipster generated app does it. In every way, you can schedule the ES reindexing if you are not allowed to modify all applications that write to your DB and can't be modified to call ES.
          – D00de
          Dec 8 '18 at 20:34




          What part of Client data are you changing. If you are changing data in DB directly ES is not aware of that change and sure, you'll need to reindex it. Change on data need to be propagated through your app, first to DB and then to ES like JHipster generated app does it. In every way, you can schedule the ES reindexing if you are not allowed to modify all applications that write to your DB and can't be modified to call ES.
          – D00de
          Dec 8 '18 at 20:34












          I'm changing it through the application, not on the DB directly. This is why I don't understand why populating is not working. My understanding was that the call to clientSearchRepository.save(result); should take care of that.
          – Fish-Guts
          Dec 9 '18 at 20:01




          I'm changing it through the application, not on the DB directly. This is why I don't understand why populating is not working. My understanding was that the call to clientSearchRepository.save(result); should take care of that.
          – Fish-Guts
          Dec 9 '18 at 20:01












          Yes, that's exactly it. That's why I said to try and generate new application and see that it works that way. clientSearchRepository extends ElasticsearchRepository, and it's mission is to keep ElasticSearch index in line with database changes. Therefor you have clientSearchRepository methods right after clientRepository in any create/update function of your backend app.
          – D00de
          Dec 10 '18 at 9:46




          Yes, that's exactly it. That's why I said to try and generate new application and see that it works that way. clientSearchRepository extends ElasticsearchRepository, and it's mission is to keep ElasticSearch index in line with database changes. Therefor you have clientSearchRepository methods right after clientRepository in any create/update function of your backend app.
          – D00de
          Dec 10 '18 at 9:46


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453585%2fpopulate-changes-directly-to-elastic-search%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Unable to find Lightning Node

          Futebolista