rwynn / monstache-site

documentation for the monstache project
https://rwynn.github.io/monstache-site/
MIT License
22 stars 31 forks source link

[About Usage] How to trans one doc to two different index in javascript plugin #29

Closed AntsKnows closed 2 years ago

AntsKnows commented 2 years ago

Is there any way to trans one doc to two different index in javascript plugin ? Such as: there is a collection db.foo with one doc {"test":"good"} and two index bar1,bar2. The config is like :

[[mapping]]
namespace = "db.foo"
index = "bar1"

[[script]]
namespace = "db.foo"
script = """
module.exports = function(doc) {
    // do something
    return doc;
}

Now i'd like to sync the doc to bar2 at the same time, what should i do?

rwynn commented 2 years ago

Unfortunately not with the javascript plugin. You can do this with a golang plugin by implementing the Process function which basically allows you to do whatever you need with the MongoDB document.

If it doesn't need to be real time then you could consider https://stackoverflow.com/questions/25144034/how-to-copy-some-elasticsearch-data-to-a-new-index.

You may also be able to do something with a processing pipeline in Elasticsearch, but I couldn't find a way to send the doc to 2 indexes with a quick search.

AntsKnows commented 2 years ago

Unfortunately not with the javascript plugin. You can do this with a golang plugin by implementing the Process function which basically allows you to do whatever you need with the MongoDB document.

If it doesn't need to be real time then you could consider https://stackoverflow.com/questions/25144034/how-to-copy-some-elasticsearch-data-to-a-new-index.

You may also be able to do something with a processing pipeline in Elasticsearch, but I couldn't find a way to send the doc to 2 indexes with a quick search.

@rwynn Thanks for your reply, do help me solve the problem.I have found the sample code in https://github.com/rwynn/monstache/issues/298