# Indexing Messages in Threads, or emulating grouping with parent-child relationship

**URL:** <https://discuss.elastic.co/t/indexing-messages-in-threads-or-emulating-grouping-with-parent-child-relationship/11762>\
**Category:** Elasticsearch\
**Created:** [May 1, 2013, 7:51am UTC](https://discuss.elastic.co/t/indexing-messages-in-threads-or-emulating-grouping-with-parent-child-relationship/11762 "2013-05-01T07:51:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Karpenkov](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@George\_Karpenkov](https://discuss.elastic.co/u/George_Karpenkov)\
**Post date:** [May 1, 2013, 7:51am UTC](https://discuss.elastic.co/t/indexing-messages-in-threads-or-emulating-grouping-with-parent-child-relationship/11762/1 "2013-05-01T07:51:18Z")

</div>

Hi All,

I'm using elastic search to index messages in a chat system. Messages work  
sort of like facebook: users talk to other users, and for a given pair of  
users their exists at most one thread. So we have threads with potentially  
very many messages, with up to 100 of messages posted per second, which we  
would like to index in nearly realtime. Given that Lucene can't really do  
updates, indexing threads is out of the question.

Consequently, we are indexing messages. However, we would like to return  
the result as "threads".  
According to a bunch of searches I did, grouping is not yet possible with  
ES and the best thing I can do if I want to, say, get 50 threads for the  
search query "hello" my best bet is to fetch ~100, group them myself and  
hope that I'll get sufficiently many.

However that does not solve the "relevance" issue: if thread A contains  
separate messages "cat" and "dog", I want to see it when I search for "cat  
AND dog". Or at least I want it to be more relevant then a thread which  
only contains the word "dog".

Another solution I've found is to make "messages" objects children of  
"threads" objects and use a has-child filter.  
However, that doesn't solve the relevance problem, because as far as I  
understand has-child, it will just give me the first thread which satisfies  
the requirements.

Any better suggestions? Am I doing something unusual?

Regards,  
George

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![aash\_dhariya](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@aash\_dhariya](https://discuss.elastic.co/u/aash_dhariya)\
**Post date:** [May 1, 2013, 7:58am UTC](https://discuss.elastic.co/t/indexing-messages-in-threads-or-emulating-grouping-with-parent-child-relationship/11762/2 "2013-05-01T07:58:25Z")

</div>

Is it possible to use messages as nested documents of a particular thread?

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Wed, May 1, 2013 at 1:21 PM, George Karpenkov [true.cheshire@gmail.com](mailto:true.cheshire@gmail.com)wrote:

> Hi All,
> 
> I'm using Elasticsearch to index messages in a chat system. Messages work  
> sort of like facebook: users talk to other users, and for a given pair of  
> users their exists at most one thread. So we have threads with potentially  
> very many messages, with up to 100 of messages posted per second, which we  
> would like to index in nearly realtime. Given that Lucene can't really do  
> updates, indexing threads is out of the question.
> 
> Consequently, we are indexing messages. However, we would like to return  
> the result as "threads".  
> According to a bunch of searches I did, grouping is not yet possible with  
> ES and the best thing I can do if I want to, say, get 50 threads for the  
> search query "hello" my best bet is to fetch ~100, group them myself and  
> hope that I'll get sufficiently many.
> 
> However that does not solve the "relevance" issue: if thread A contains  
> separate messages "cat" and "dog", I want to see it when I search for "cat  
> AND dog". Or at least I want it to be more relevant then a thread which  
> only contains the word "dog".
> 
> Another solution I've found is to make "messages" objects children of  
> "threads" objects and use a has-child filter.  
> However, that doesn't solve the relevance problem, because as far as I  
> understand has-child, it will just give me the first thread which satisfies  
> the requirements.
> 
> Any better suggestions? Am I doing something unusual?
> 
> Regards,  
> George
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Thanks,  
Aash

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![George\_Karpenkov\_2](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@George\_Karpenkov\_2](https://discuss.elastic.co/u/George_Karpenkov_2)\
**Post date:** [May 1, 2013, 8:13am UTC](https://discuss.elastic.co/t/indexing-messages-in-threads-or-emulating-grouping-with-parent-child-relationship/11762/3 "2013-05-01T08:13:30Z")

</div>

Unfortunately as far as I understand ES inserting inner document will  
require re-indexing of the entire thread.

On Wed, May 1, 2013 at 5:58 PM, aash dhariya [aash.discover@gmail.com](mailto:aash.discover@gmail.com)wrote:

> Is it possible to use messages as nested documents of a particular thread?  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/nested-type/)
> 
> On Wed, May 1, 2013 at 1:21 PM, George Karpenkov [true.cheshire@gmail.com](mailto:true.cheshire@gmail.com)wrote:
> 
> > Hi All,
> > 
> > I'm using Elasticsearch to index messages in a chat system. Messages  
> > work sort of like facebook: users talk to other users, and for a given pair  
> > of users their exists at most one thread. So we have threads with  
> > potentially very many messages, with up to 100 of messages posted per  
> > second, which we would like to index in nearly realtime. Given that Lucene  
> > can't really do updates, indexing threads is out of the question.
> > 
> > Consequently, we are indexing messages. However, we would like to return  
> > the result as "threads".  
> > According to a bunch of searches I did, grouping is not yet possible with  
> > ES and the best thing I can do if I want to, say, get 50 threads for the  
> > search query "hello" my best bet is to fetch ~100, group them myself and  
> > hope that I'll get sufficiently many.
> > 
> > However that does not solve the "relevance" issue: if thread A contains  
> > separate messages "cat" and "dog", I want to see it when I search for "cat  
> > AND dog". Or at least I want it to be more relevant then a thread which  
> > only contains the word "dog".
> > 
> > Another solution I've found is to make "messages" objects children of  
> > "threads" objects and use a has-child filter.  
> > However, that doesn't solve the relevance problem, because as far as I  
> > understand has-child, it will just give me the first thread which satisfies  
> > the requirements.
> > 
> > Any better suggestions? Am I doing something unusual?
> > 
> > Regards,  
> > George
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> Thanks,  
> Aash
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/LBwTcyAgiM8/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/LBwTcyAgiM8/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:38am UTC](https://discuss.elastic.co/t/indexing-messages-in-threads-or-emulating-grouping-with-parent-child-relationship/11762/4 "2017-07-06T02:38:53Z")

</div>


