Algolia重复

Algolia正常工作时遇到了一些麻烦。 我正在使用NodeJS,并试图在我的数据库和Algolia之间进行一些同步,但由于某种原因,一些重复的东西似乎随机popup。

在这里输入图像描述

正如你所看到的,在某些情况下,除了主题名称外,还有两个不同的条目会popup完全不同的数据。 我没有在其他任何地方运行add-to-algolia代码,并且UUID已closures,因为我放入的条目在它们前面有“topic-”。

function loadNewTweets(){ console.log("Checking..."); var tweets; var topics; var referenceTopics; Promise.all([ //stuff ]) .then(function(data){ topics = [ //data ] return Promise.each(topics, function(topic, index){ return new Promise(function(res,rej){ Promise.all([ //things ]) .then(function(r){ var id = 'topic-'+uuid.v4(); if(!topicDB){ var obj = { //data } console.log("Adding", topic.topic, "to topic DB + Algolia"); return new Promise(function(res,rej){ var dbInstance; Database.models.Topic.create(obj) .then(function(topic){ dbInstance = topic; return Search.addData('topics', [dbInstance]) }) .then(function(content){ dbInstance.algoliaId = content.objectIDs[0]; return dbInstance.save(['algoliaId']); }) .then(function(){ return res(); }) }) } }) .then(function(){ return res(); }) }) }) }) .then(function(){ return Database.models.Topic.findAll({}) }) .then(function(topicsDB){ //If a topic is in the database, but not the topics array. //Loop through each database entry. Promise.each(topicsDB, function(topic){ var del = true; //Go through topics array for(var i=0;i<topics.length;i++){ //If a topic in the array matches a database entry, dont remove it. if(topics[i].topic == topic.topic){ del = false; } } //If no entry was found in the array for this topic in the database, remove it from the database and Algolia. if(del){ console.log("Deleting", topic.topic, "from topic DB + Algolia", topic.algoliaId); Search.delete('topics', [topic.algoliaId]) .then(function(){ topic.destroy(); }) } }) }) } 

有什么我失踪的select? 任何帮助,将不胜感激。

编辑:似乎有重复和原来的某种关系,但我仍然不知道是什么原因造成的。

在这里输入图像描述

(原谅吧)

有重复,因为您没有使用objectID来唯一标识您的logging。 通常主键可以很好地作为对象标识符 。 如果不指定,Algolia会自动分配一个,这意味着它不会有重复。

所以这很尴尬。

我忘记了一个login服务器也是索引的贡献。