The data that comes back from GraphQL is not ideal for input to Elastic Search which is designed for full-text searching, which means it loses context when searching arrays. Consider this response from some fictional GraphQL API.

To make a success of this in Elastic search we need to turn it back into a tabular format, a little like you might get back from a complex SQL join. Something like this.

That’s a little more complex than simple object flattening, as we need to create a duplicate row each time there is an array element, and of course, these arrays might occur at any level.

The code

That will give this result
We can take that one stage further and convert the result into a tabular format (ideal for writing to a sheet)
Which gives this result, with the header row in the first element

Putting it together

Assuming the JSON data earlier in the article is in a variable called films, here’s the whole thing
You can find an Apps Script version of this here.
Since G+ is closed, you can now star and follow post announcements and discussions on Github, here