0

I had a document like below I need to send this document to elasticsearch as 3 documents with title contains each of array and I am using compose transporter to send my documents to elasticsearch. How can I achieve this?

{
    "_id" : ObjectId("5c6bb079d209fd4dd5b4d6ce"),
    "title" : [ 
        "ram", 
        "sham", 
        "bhim"
    ]
}

and my expected output in elasticsearch is like this with different ids

{
    "_id" : ObjectId("5c6bb079d209fd4dd5b4d6ce"),
    "title" : "ram"

}

{
    "_id" : ObjectId("5c6bb079d209fd4dd5b4d6ce"),
    "title" : "sham"

}
{
    "_id" : ObjectId("5c6bb079d209fd4dd5b4d6ce"),
    "title" : "bhim"

}
satya
  • 152
  • 2
  • 8

1 Answers1

0

You can use the below query to achieve it,

db.collectionName.aggregate([{"$unwind":"$title"}])

Thanks, Mohamed Rilwan

Rilwan
  • 88
  • 11