Closed xiangyiliu18 closed 5 years ago
my scripts: [[script]] namespace = "firewall.questions" script = """ module.exports = function(doc){ if(doc.user){ doc.user = findId(doc.user, { database: "firewall", collection: "user" }) } doc.answer_count = doc.answers.length; doc.viewcount = doc.viewers.length; doc.score = doc.upvote.length - doc.downvote.length; return .omit(doc,"viewers", "answers", "upvote", "downvote"); } """
findId
returns a document if it's found in the given database/collection and null
if it is not found. I think you are seeing that the document is not found in the collection and null
is being returned and set into the document for indexing.
yes. you are right. I got user right now, but how can i keep the field with null value or empty array
I got oneissure about findId. Please tell me what do i need to figure it out
INFO 2019/05/08 17:07:20 Started monstache version 3.24.2 INFO 2019/05/08 17:07:20 Successfully connected to MongoDB version 4.0.9 INFO 2019/05/08 17:07:20 Successfully connected to Elasticsearch version 2.3.1 INFO 2019/05/08 17:07:20 Listening for events INFO 2019/05/08 17:07:20 Sending systemd READY=1 WARN 2019/05/08 17:07:20 Systemd notification not supported (i.e. NOTIFY_SOCKET is unset) INFO 2019/05/08 17:07:20 Watching changes on collection firewall.questions ERROR 2019/05/08 17:07:20 Error in function findId: not found
Anther issue is: if i did not use script. my data in db and elasticsearch are exactly same. If i use the script, i will miss two fields, like user. and got null for empty array