我很难让阿尔戈利亚正常工作。我正在使用NodeJS,并试图在我的数据库和Algolia之间进行一些同步,但是由于某种原因,大量的副本似乎随机出现。

正如您所看到的,在某些情况下,除了主题名称之外,两个不同的条目会弹出完全不同的数据。我不会在其他地方运行添加到算法的代码,并且UUID是关闭的,因为我把它们放在前面的条目有“主题-”。
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();
})
}
})
})
}
我错过了什么选择吗?任何帮助都将不胜感激。
编辑:复制和原版之间似乎有某种关系,但我仍然不知道是什么原因造成的。

(原谅律师)
发布于 2017-07-13 16:01:38
所以这太尴尬了。
我忘记了一个临时服务器,它也对索引做出了贡献。
发布于 2017-07-17 14:29:50
存在重复,因为您没有使用objectID来唯一地标识记录。通常,主键与objectID一样工作良好。如果您不指定一个,Algolia将自动分配一个,这意味着它将很难没有重复。
{
name: 'some name',
objectID: 'the id of the data in my database'
}文档中有一些示例:https://www.algolia.com/doc/api-reference/api-methods/save-objects/#examples
https://stackoverflow.com/questions/45071684
复制相似问题