I would like to use Elasticsearch to index and search a threaded conversation, like a blog's comments where there are top-level comments and replies to those comments.
I have tried making a single document like this, with a Nested comments
field, with each comment having an ID, a parent ID, and a list of child reply IDs.
{
"comments": [
{
"id": 1,
"text": "nice post",
"replies": [ 2 ]
},
{
"id": 2,
"parent": 1,
"text": "Thanks for reading my blog!"
},
{
"id": 3,
"text": "very helpful"
}
]
}
This works to an extent because I can search through the comments.text
fields and find matches. But I think the API gives me back only the matching text, removed from the context of the adjacent fields that tell me where the comment is in the discussion.
Is this a good way to store this data?
I could also put each comment as a separate document, with a common conversation ID (e.g., the blog post ID), and the parent and child IDs. I'm not sure if this is a good use case for "join" queries or not.