1

I have data in Json dataframe like below.

{"nm": 1233, "date": "2017-01-23", "name": [],"id": "9253194"}
{"nm": 1234, "date": "2017-01-23", "name": [],"id": "9253196"}
{"nm": 1235, "date": "2017-01-23", "name": [],"id": "9253195"}

how can add a new row with an indexed column to insert in to elastic search in scala.

{"create": {"_type": "usd", "_id": "92531964", "_index": "amount"}}
{"nm": 1233, "date": "2017-01-23", "name": [],"id": "9253194"}
{"create": {"_type": "usd", "_id": "92531966", "_index": "amount"}}
{"nm": 1234, "date": "2017-01-23", "name": [],"id": "9253196"}
{"create": {"_type": "usd", "_id": "92531965", "_index": "amount"}}
{"nm": 1235, "date": "2017-01-23", "name": [],"id": "9253195"}

here _id I am deriving from existing column and _type, _index are constants.

1 Answer 1

1

Use flatMap:

input.flatMap { x => Seq(x, transform(x)) }

Since these records have different schema, you might have to output them just as strings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.