The repeat problem when I use the index.addObjects()

When I use the vue-instantSearch and import Data from a json file, the first time algolia correctly adds the new index in my account, but when I refresh my web page,the new index repeatly adds the data from my json file.The textData is the name of my json file.How can I deal with this problem?

const records = testData;
index.addObjects(records, function(err,content) {
    console.log(err);
});

Hey @Lindacsy,

When using a search engine, there are two distinct phases. Indexing and searching. What you want to do is set up your index with addObjects somewhere server side or on beforehand via the dashboard. When you’re searching (with Vue InstantSearch for example), you won’t need to add any more objects, but rather use the index that you made.

Also, if you’re having objectID in the object, even if you push it multiple times, it will override, and not make new records.

Hope that helped!

Thank you very much, your answer helps me solve this problem. I give each data a unique objectID, and now I can add and update my data. However, why I need to refresh the web page twice or three times and then the changes of my data will be presented? Do you have some ideas to realize the synchronized updation?
Thanks a lot!

Hey @Lindacsy, can you describe the flow you’re having now? I’m not sure if I understood exactly how you’re doing the indexing now. Is it still happening every time someone opens the page?

The exactly problem that I meet is, I import data from a file/database, and then I update the data of the file, but my web page doesn’t have any changes, I must refresh twice or three times. I just do some tests and maybe the refresh rate is limited because of our firewall…

Indexing is asynchronous, that means it can take a few seconds between you doing .saveObject and the object being visible in the search. What I think you’re doing is the indexing on every time the people go to the page, while indexing should only be done when the data changes. Can you make your project visible to me, or put a smaller version of what you made on GitHub?

Hey haroen,
I want to ask you what is the principle of vue InstantSearch.
And if I import data from local database, then I use the partialUpdateObjects() function, the data will update in my webpage and algolia dashboard. I want to know whether the data will update in my local database? What can I do to realize the updation in my local database?
Best wishes~

Hey @Lindacsy,

There are three steps in making a search experience.

  1. synchronise your data with Algolia
  2. set settings for your indices
  3. search through the indices

Vue InstantSearch is made for the last step, where there already is an index, and you want to show what’s in it, filter it etc.

The first step is something you’ll usually do in a different process on a server or something synchronised with your database. There you’ll do an initial import of all data, and subsequently update when things happen in the database. The exact procedure depends a bit on which ORM (if any) and which database you use. What are you using?

see also https://www.algolia.com/doc/guides/getting-started/the-implementation-process/ and other pages in the documentation.

Hope that helped!