I have a Spark cluster and have to index JSON data to Elastic Search (ES). There is a column as follows (two samples only):
"ADDRESS": "PO box 1234, Lahore"
"ADDRESS": [ "PO box 5678, Karachi", "new city Lahore"]
The problem with above column is that, in some records, it is appearing as string and in some other cases, it is appearing as array of string. I have tested above case in ES, there is no issue in ES, it can index both cases without issue (if directly indexed).
I have written a Spark (pyspark) job to read large JSON and then insert it to ES. In Spark schema, it is showing this field as string instead of array. Now, when I insert data into ES, I get following responses
"ADDRESS": "PO box 1234, Lahore",
"ADDRESS": "[\"PO box 5678, Karachi\", \"new city Lahore\"]",
Instead of showing as array data, it is showing as string. Now, where is the issue ? I am reading JSON as follows:
df = spark.read.option("multiline", "false").json(data_path)
