# Modeling products and category

**URL:** <https://discuss.elastic.co/t/modeling-products-and-category/13330>\
**Category:** Elasticsearch\
**Created:** [August 26, 2013, 5:33pm UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330 "2013-08-26T17:33:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hitchhikar](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@hitchhikar](https://discuss.elastic.co/u/hitchhikar)\
**Post date:** [August 26, 2013, 5:33pm UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330/1 "2013-08-26T17:33:29Z")

</div>

Hi All  
I am quite confused over a type mapping to fit my model.  
Main type is "product". A product can be associated with multiple  
categories. For simplicity say categories are not nested but a product cn  
have more than 1 category.  
Now I am thinking to create an index per category and store products routed  
to that category name.  
This way if Product#1 is associated with Category#A and Category#B then it  
will indexed in 2 index (category A and B index). the doc will be exactly  
same in both.  
This is okay (i suppose).  
But if I run any search across all indices and matching this document, then  
the resultset will contain this Product#1 twice.  
How can i avoid that?

( I dont want to store products in single index with category as array  
field and corresponding aliases with filtered on category)  
Do suggest me how this can be done or done better.

--  
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:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [August 27, 2013, 3:59am UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330/2 "2013-08-27T03:59:56Z")

</div>

I think you need to explain why you don't want to do it the simple and  
straightforward way. The key to using search effectively is to denormalize  
your data, not build some system that does one query well and will fall  
flat outside of that small window.

You are trying to get prematurely clever. Don't use routing unless there is  
a guaranteed 1 to 1 mapping between doc to routing value, and even then  
only do it if it makes sense.

Best Regards,  
Paul

On Monday, August 26, 2013 11:33:29 AM UTC-6, S wrote:

> Hi All  
> I am quite confused over a type mapping to fit my model.  
> Main type is "product". A product can be associated with multiple  
> categories. For simplicity say categories are not nested but a product cn  
> have more than 1 category.  
> Now I am thinking to create an index per category and store products  
> routed to that category name.  
> This way if Product#1 is associated with Category#A and Category#B then it  
> will indexed in 2 index (category A and B index). the doc will be exactly  
> same in both.  
> This is okay (i suppose).  
> But if I run any search across all indices and matching this document,  
> then the resultset will contain this Product#1 twice.  
> How can i avoid that?
> 
> ( I dont want to store products in single index with category as array  
> field and corresponding aliases with filtered on category)  
> Do suggest me how this can be done or done better.

--  
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:** ![hitchhikar](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@hitchhikar](https://discuss.elastic.co/u/hitchhikar)\
**Post date:** [August 27, 2013, 12:43pm UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330/3 "2013-08-27T12:43:07Z")

</div>

@Paul your reply solves no purpose. You havnt taken note of q i am asking  
and just quoting your opinions re elasticsearch.  
Its better to be clever in planning thn stupid in execution. If 1 query is  
the most important query for which i am using elasticsearch then I will  
model my data to suit that.

That said, I was experiencing data hotspots with 1 index...filtered/routed  
aliases(per category) . As the guide suggests that if there are hotspots  
then convert that into index, So I am trying to model each category as  
index now. The issue is with this approach i have same document in multiple  
index (as product can be assoc with multiple categories).  
I am not sure that thats a good approach. So wud appreciate if can get some  
advice

On Tuesday, August 27, 2013 9:29:56 AM UTC+5:30, ppearcy wrote:

> I think you need to explain why you don't want to do it the simple and  
> straightforward way. The key to using search effectively is to  
> denormalize your data, not build some system that does one query well and  
> will fall flat outside of that small window.
> 
> You are trying to get prematurely clever. Don't use routing unless there  
> is a guaranteed 1 to 1 mapping between doc to routing value, and even then  
> only do it if it makes sense.
> 
> Best Regards,  
> Paul
> 
> On Monday, August 26, 2013 11:33:29 AM UTC-6, S wrote:
> 
> > Hi All  
> > I am quite confused over a type mapping to fit my model.  
> > Main type is "product". A product can be associated with multiple  
> > categories. For simplicity say categories are not nested but a product cn  
> > have more than 1 category.  
> > Now I am thinking to create an index per category and store products  
> > routed to that category name.  
> > This way if Product#1 is associated with Category#A and Category#B then  
> > it will indexed in 2 index (category A and B index). the doc will be  
> > exactly same in both.  
> > This is okay (i suppose).  
> > But if I run any search across all indices and matching this document,  
> > then the resultset will contain this Product#1 twice.  
> > How can i avoid that?
> > 
> > ( I dont want to store products in single index with category as array  
> > field and corresponding aliases with filtered on category)  
> > Do suggest me how this can be done or done better.

--  
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:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [August 27, 2013, 2:46pm UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330/4 "2013-08-27T14:46:12Z")

</div>

Apologies, I did not mean to offend or have a meaningless reply, should  
have just left it at "more info, please."

To answer this question: "But if I run any search across all indices and  
matching this document, then the resultset will contain this Product#1  
twice.  
How can i avoid that?"

Currently, you can't avoid dups unless you request more matches than you  
need and dedup client side. There is likely work in the pipeline for  
grouping results which will likely allow you to collapse these down, but I  
don't know when that will be available. FWIW, I think Solr has the  
capability to collapse results, but not sure if it does routing.

Can you elaborate on your "data hotspots" and include as many details as  
possible on your configuration (nodes, settings, mappings, data, queries  
etc).

Best Regards,  
Paul

On Tuesday, August 27, 2013 6:43:07 AM UTC-6, S wrote:

> @Paul your reply solves no purpose. You havnt taken note of q i am asking  
> and just quoting your opinions re elasticsearch.  
> Its better to be clever in planning thn stupid in execution. If 1 query is  
> the most important query for which i am using elasticsearch then I will  
> model my data to suit that.
> 
> That said, I was experiencing data hotspots with 1 index...filtered/routed  
> aliases(per category) . As the guide suggests that if there are hotspots  
> then convert that into index, So I am trying to model each category as  
> index now. The issue is with this approach i have same document in multiple  
> index (as product can be assoc with multiple categories).  
> I am not sure that thats a good approach. So wud appreciate if can get  
> some advice
> 
> On Tuesday, August 27, 2013 9:29:56 AM UTC+5:30, ppearcy wrote:
> 
> > I think you need to explain why you don't want to do it the simple and  
> > straightforward way. The key to using search effectively is to  
> > denormalize your data, not build some system that does one query well and  
> > will fall flat outside of that small window.
> > 
> > You are trying to get prematurely clever. Don't use routing unless there  
> > is a guaranteed 1 to 1 mapping between doc to routing value, and even then  
> > only do it if it makes sense.
> > 
> > Best Regards,  
> > Paul
> > 
> > On Monday, August 26, 2013 11:33:29 AM UTC-6, S wrote:
> > 
> > > Hi All  
> > > I am quite confused over a type mapping to fit my model.  
> > > Main type is "product". A product can be associated with multiple  
> > > categories. For simplicity say categories are not nested but a product cn  
> > > have more than 1 category.  
> > > Now I am thinking to create an index per category and store products  
> > > routed to that category name.  
> > > This way if Product#1 is associated with Category#A and Category#B then  
> > > it will indexed in 2 index (category A and B index). the doc will be  
> > > exactly same in both.  
> > > This is okay (i suppose).  
> > > But if I run any search across all indices and matching this document,  
> > > then the resultset will contain this Product#1 twice.  
> > > How can i avoid that?
> > > 
> > > ( I dont want to store products in single index with category as array  
> > > field and corresponding aliases with filtered on category)  
> > > Do suggest me how this can be done or done better.

--  
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:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [August 27, 2013, 3:00pm UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330/5 "2013-08-27T15:00:22Z")

</div>

Btw, if you haven't already, make sure you read this article:

> **[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.

A key excerpt:  
When a document is indexed, you may only specify a single routing value. It  
doesn’t make sense for a document to be routed to multiple shards!

On Tuesday, August 27, 2013 8:46:12 AM UTC-6, ppearcy wrote:

> Apologies, I did not mean to offend or have a meaningless reply, should  
> have just left it at "more info, please."
> 
> To answer this question: "But if I run any search across all indices and  
> matching this document, then the resultset will contain this Product#1  
> twice.  
> How can i avoid that?"
> 
> Currently, you can't avoid dups unless you request more matches than you  
> need and dedup client side. There is likely work in the pipeline for  
> grouping results which will likely allow you to collapse these down, but I  
> don't know when that will be available. FWIW, I think Solr has the  
> capability to collapse results, but not sure if it does routing.
> 
> Can you elaborate on your "data hotspots" and include as many details as  
> possible on your configuration (nodes, settings, mappings, data, queries  
> etc).
> 
> Best Regards,  
> Paul
> 
> On Tuesday, August 27, 2013 6:43:07 AM UTC-6, S wrote:
> 
> > @Paul your reply solves no purpose. You havnt taken note of q i am asking  
> > and just quoting your opinions re elasticsearch.  
> > Its better to be clever in planning thn stupid in execution. If 1 query  
> > is the most important query for which i am using elasticsearch then I will  
> > model my data to suit that.
> > 
> > That said, I was experiencing data hotspots with 1  
> > index...filtered/routed aliases(per category) . As the guide suggests that  
> > if there are hotspots then convert that into index, So I am trying to model  
> > each category as index now. The issue is with this approach i have same  
> > document in multiple index (as product can be assoc with multiple  
> > categories).  
> > I am not sure that thats a good approach. So wud appreciate if can get  
> > some advice
> > 
> > On Tuesday, August 27, 2013 9:29:56 AM UTC+5:30, ppearcy wrote:
> > 
> > > I think you need to explain why you don't want to do it the simple and  
> > > straightforward way. The key to using search effectively is to  
> > > denormalize your data, not build some system that does one query well and  
> > > will fall flat outside of that small window.
> > > 
> > > You are trying to get prematurely clever. Don't use routing unless there  
> > > is a guaranteed 1 to 1 mapping between doc to routing value, and even then  
> > > only do it if it makes sense.
> > > 
> > > Best Regards,  
> > > Paul
> > > 
> > > On Monday, August 26, 2013 11:33:29 AM UTC-6, S wrote:
> > > 
> > > > Hi All  
> > > > I am quite confused over a type mapping to fit my model.  
> > > > Main type is "product". A product can be associated with multiple  
> > > > categories. For simplicity say categories are not nested but a product cn  
> > > > have more than 1 category.  
> > > > Now I am thinking to create an index per category and store products  
> > > > routed to that category name.  
> > > > This way if Product#1 is associated with Category#A and Category#B then  
> > > > it will indexed in 2 index (category A and B index). the doc will be  
> > > > exactly same in both.  
> > > > This is okay (i suppose).  
> > > > But if I run any search across all indices and matching this document,  
> > > > then the resultset will contain this Product#1 twice.  
> > > > How can i avoid that?
> > > > 
> > > > ( I dont want to store products in single index with category as array  
> > > > field and corresponding aliases with filtered on category)  
> > > > Do suggest me how this can be done or done better.

--  
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:** ![hitchhikar](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@hitchhikar](https://discuss.elastic.co/u/hitchhikar)\
**Post date:** [August 27, 2013, 3:06pm UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330/6 "2013-08-27T15:06:58Z")

</div>

Alright I will provide more info in a while.  
But again you are digressing from the question (or atleast my confusion).  
That key excerpt talks about routing. Obviously a single document cant be  
routed (hence indexed) in multiple shards.  
I am clear on routing and all.  
I am talking abt indexing a document in 2 different index (say  
index:category\_A and index:category\_B coz product is assoc with both  
categories and i am thinking to keep all categories as sep index).

I appreciate you taking your time out.

On Tuesday, August 27, 2013 8:30:22 PM UTC+5:30, ppearcy wrote:

> Btw, if you haven't already, make sure you read this article:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/customizing-your-document-routing/)
> 
> A key excerpt:  
> When a document is indexed, you may only specify a single routing value.  
> It doesn’t make sense for a document to be routed to multiple shards!
> 
> On Tuesday, August 27, 2013 8:46:12 AM UTC-6, ppearcy wrote:
> 
> > Apologies, I did not mean to offend or have a meaningless reply, should  
> > have just left it at "more info, please."
> > 
> > To answer this question: "But if I run any search across all indices and  
> > matching this document, then the resultset will contain this Product#1  
> > twice.  
> > How can i avoid that?"
> > 
> > Currently, you can't avoid dups unless you request more matches than you  
> > need and dedup client side. There is likely work in the pipeline for  
> > grouping results which will likely allow you to collapse these down, but I  
> > don't know when that will be available. FWIW, I think Solr has the  
> > capability to collapse results, but not sure if it does routing.
> > 
> > Can you elaborate on your "data hotspots" and include as many details as  
> > possible on your configuration (nodes, settings, mappings, data, queries  
> > etc).
> > 
> > Best Regards,  
> > Paul
> > 
> > On Tuesday, August 27, 2013 6:43:07 AM UTC-6, S wrote:
> > 
> > > @Paul your reply solves no purpose. You havnt taken note of q i am  
> > > asking and just quoting your opinions re elasticsearch.  
> > > Its better to be clever in planning thn stupid in execution. If 1 query  
> > > is the most important query for which i am using elasticsearch then I will  
> > > model my data to suit that.
> > > 
> > > That said, I was experiencing data hotspots with 1  
> > > index...filtered/routed aliases(per category) . As the guide suggests that  
> > > if there are hotspots then convert that into index, So I am trying to model  
> > > each category as index now. The issue is with this approach i have same  
> > > document in multiple index (as product can be assoc with multiple  
> > > categories).  
> > > I am not sure that thats a good approach. So wud appreciate if can get  
> > > some advice
> > > 
> > > On Tuesday, August 27, 2013 9:29:56 AM UTC+5:30, ppearcy wrote:
> > > 
> > > > I think you need to explain why you don't want to do it the simple and  
> > > > straightforward way. The key to using search effectively is to  
> > > > denormalize your data, not build some system that does one query well and  
> > > > will fall flat outside of that small window.
> > > > 
> > > > You are trying to get prematurely clever. Don't use routing unless  
> > > > there is a guaranteed 1 to 1 mapping between doc to routing value, and even  
> > > > then only do it if it makes sense.
> > > > 
> > > > Best Regards,  
> > > > Paul
> > > > 
> > > > On Monday, August 26, 2013 11:33:29 AM UTC-6, S wrote:
> > > > 
> > > > > Hi All  
> > > > > I am quite confused over a type mapping to fit my model.  
> > > > > Main type is "product". A product can be associated with multiple  
> > > > > categories. For simplicity say categories are not nested but a product cn  
> > > > > have more than 1 category.  
> > > > > Now I am thinking to create an index per category and store products  
> > > > > routed to that category name.  
> > > > > This way if Product#1 is associated with Category#A and Category#B  
> > > > > then it will indexed in 2 index (category A and B index). the doc will be  
> > > > > exactly same in both.  
> > > > > This is okay (i suppose).  
> > > > > But if I run any search across all indices and matching this document,  
> > > > > then the resultset will contain this Product#1 twice.  
> > > > > How can i avoid that?
> > > > > 
> > > > > ( I dont want to store products in single index with category as array  
> > > > > field and corresponding aliases with filtered on category)  
> > > > > Do suggest me how this can be done or done better.

--  
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:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [August 28, 2013, 5:42pm UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330/7 "2013-08-28T17:42:04Z")

</div>

There is a good reason that ES doesn't support multi valued routing, it  
just doesn't work without the capability to dedup docs (aka field  
collapsing), which doesn't exist.

If you want to index a single doc to multiple category indexes, your query  
must either:  
-- Only hit a single category index at a time

- Request a large result set in your query and dedup client side. If you do  
this, you can't paginate unless you pull all results down, which is a bad  
idea.

On Tuesday, August 27, 2013 9:06:58 AM UTC-6, S wrote:

> Alright I will provide more info in a while.  
> But again you are digressing from the question (or atleast my confusion).  
> That key excerpt talks about routing. Obviously a single document cant be  
> routed (hence indexed) in multiple shards.  
> I am clear on routing and all.  
> I am talking abt indexing a document in 2 different index (say  
> index:category\_A and index:category\_B coz product is assoc with both  
> categories and i am thinking to keep all categories as sep index).
> 
> I appreciate you taking your time out.
> 
> On Tuesday, August 27, 2013 8:30:22 PM UTC+5:30, ppearcy wrote:
> 
> > Btw, if you haven't already, make sure you read this article:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/customizing-your-document-routing/)
> > 
> > A key excerpt:  
> > When a document is indexed, you may only specify a single routing value.  
> > It doesn’t make sense for a document to be routed to multiple shards!
> > 
> > On Tuesday, August 27, 2013 8:46:12 AM UTC-6, ppearcy wrote:
> > 
> > > Apologies, I did not mean to offend or have a meaningless reply, should  
> > > have just left it at "more info, please."
> > > 
> > > To answer this question: "But if I run any search across all indices  
> > > and matching this document, then the resultset will contain this Product#1  
> > > twice.  
> > > How can i avoid that?"
> > > 
> > > Currently, you can't avoid dups unless you request more matches than you  
> > > need and dedup client side. There is likely work in the pipeline for  
> > > grouping results which will likely allow you to collapse these down, but I  
> > > don't know when that will be available. FWIW, I think Solr has the  
> > > capability to collapse results, but not sure if it does routing.
> > > 
> > > Can you elaborate on your "data hotspots" and include as many details as  
> > > possible on your configuration (nodes, settings, mappings, data, queries  
> > > etc).
> > > 
> > > Best Regards,  
> > > Paul
> > > 
> > > On Tuesday, August 27, 2013 6:43:07 AM UTC-6, S wrote:
> > > 
> > > > @Paul your reply solves no purpose. You havnt taken note of q i am  
> > > > asking and just quoting your opinions re elasticsearch.  
> > > > Its better to be clever in planning thn stupid in execution. If 1 query  
> > > > is the most important query for which i am using elasticsearch then I will  
> > > > model my data to suit that.
> > > > 
> > > > That said, I was experiencing data hotspots with 1  
> > > > index...filtered/routed aliases(per category) . As the guide suggests that  
> > > > if there are hotspots then convert that into index, So I am trying to model  
> > > > each category as index now. The issue is with this approach i have same  
> > > > document in multiple index (as product can be assoc with multiple  
> > > > categories).  
> > > > I am not sure that thats a good approach. So wud appreciate if can get  
> > > > some advice
> > > > 
> > > > On Tuesday, August 27, 2013 9:29:56 AM UTC+5:30, ppearcy wrote:
> > > > 
> > > > > I think you need to explain why you don't want to do it the simple and  
> > > > > straightforward way. The key to using search effectively is to  
> > > > > denormalize your data, not build some system that does one query well and  
> > > > > will fall flat outside of that small window.
> > > > > 
> > > > > You are trying to get prematurely clever. Don't use routing unless  
> > > > > there is a guaranteed 1 to 1 mapping between doc to routing value, and even  
> > > > > then only do it if it makes sense.
> > > > > 
> > > > > Best Regards,  
> > > > > Paul
> > > > > 
> > > > > On Monday, August 26, 2013 11:33:29 AM UTC-6, S wrote:
> > > > > 
> > > > > > Hi All  
> > > > > > I am quite confused over a type mapping to fit my model.  
> > > > > > Main type is "product". A product can be associated with multiple  
> > > > > > categories. For simplicity say categories are not nested but a product cn  
> > > > > > have more than 1 category.  
> > > > > > Now I am thinking to create an index per category and store products  
> > > > > > routed to that category name.  
> > > > > > This way if Product#1 is associated with Category#A and Category#B  
> > > > > > then it will indexed in 2 index (category A and B index). the doc will be  
> > > > > > exactly same in both.  
> > > > > > This is okay (i suppose).  
> > > > > > But if I run any search across all indices and matching this  
> > > > > > document, then the resultset will contain this Product#1 twice.  
> > > > > > How can i avoid that?
> > > > > > 
> > > > > > ( I dont want to store products in single index with category as  
> > > > > > array field and corresponding aliases with filtered on category)  
> > > > > > Do suggest me how this can be done or done better.

--  
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:** ![Randall\_McRee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/randall_mcree/32/47177_2.png) [@Randall\_McRee](https://discuss.elastic.co/u/Randall_McRee)\
**Post date:** [August 28, 2013, 6:00pm UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330/8 "2013-08-28T18:00:28Z")

</div>

Dear original poster,  
All of these problems seem to stem from your original decision of how to  
store the category information for a product. In my view, based on  
experience, you simply bypassed the best way to do this. When this is  
pointed out you say:

_( I dont want to store products in single index with category as array  
field and corresponding aliases with filtered on category)_

But some variant of this is _exactly_ the correct way to do this according  
to various successful indices in production today. (Don't know why you  
mention aliases, though??)

So perhaps rather than focusing on why routing is broken or why multiple  
indices don't work correctly in your view--perhaps start another thread on  
correct design? Tell us why you cannot simply store the category  
information along with the product? What kind of queries do you need to  
support? Go up a level.

On Wed, Aug 28, 2013 at 10:42 AM, ppearcy [ppearcy@gmail.com](mailto:ppearcy@gmail.com) wrote:

> There is a good reason that ES doesn't support multi valued routing, it  
> just doesn't work without the capability to dedup docs (aka field  
> collapsing), which doesn't exist.
> 
> If you want to index a single doc to multiple category indexes, your query  
> must either:  
> -- Only hit a single category index at a time
> 
> - Request a large result set in your query and dedup client side. If you  
> do this, you can't paginate unless you pull all results down, which is a  
> bad idea.
> 
> On Tuesday, August 27, 2013 9:06:58 AM UTC-6, S wrote:
> 
> > Alright I will provide more info in a while.  
> > But again you are digressing from the question (or atleast my confusion).  
> > That key excerpt talks about routing. Obviously a single document cant be  
> > routed (hence indexed) in multiple shards.  
> > I am clear on routing and all.  
> > I am talking abt indexing a document in 2 different index (say  
> > index:category\_A and index:category\_B coz product is assoc with both  
> > categories and i am thinking to keep all categories as sep index).
> > 
> > I appreciate you taking your time out.
> > 
> > On Tuesday, August 27, 2013 8:30:22 PM UTC+5:30, ppearcy wrote:
> > 
> > > Btw, if you haven't already, make sure you read this article:  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/ **blog/customizing-your-** document-routing/)[http://www.elasticsearch.org/blog/customizing-your-document-routing/](http://www.elasticsearch.org/blog/customizing-your-document-routing/)
> > > 
> > > A key excerpt:  
> > > When a document is indexed, you may only specify a single routing value.  
> > > It doesn’t make sense for a document to be routed to multiple shards!
> > > 
> > > On Tuesday, August 27, 2013 8:46:12 AM UTC-6, ppearcy wrote:
> > > 
> > > > Apologies, I did not mean to offend or have a meaningless reply, should  
> > > > have just left it at "more info, please."
> > > > 
> > > > To answer this question: "But if I run any search across all indices  
> > > > and matching this document, then the resultset will contain this Product#1  
> > > > twice.  
> > > > How can i avoid that?"
> > > > 
> > > > Currently, you can't avoid dups unless you request more matches than  
> > > > you need and dedup client side. There is likely work in the pipeline for  
> > > > grouping results which will likely allow you to collapse these down, but I  
> > > > don't know when that will be available. FWIW, I think Solr has the  
> > > > capability to collapse results, but not sure if it does routing.
> > > > 
> > > > Can you elaborate on your "data hotspots" and include as many details  
> > > > as possible on your configuration (nodes, settings, mappings, data, queries  
> > > > etc).
> > > > 
> > > > Best Regards,  
> > > > Paul
> > > > 
> > > > On Tuesday, August 27, 2013 6:43:07 AM UTC-6, S wrote:
> > > > 
> > > > > @Paul your reply solves no purpose. You havnt taken note of q i am  
> > > > > asking and just quoting your opinions re elasticsearch.  
> > > > > Its better to be clever in planning thn stupid in execution. If 1  
> > > > > query is the most important query for which i am using elasticsearch then I  
> > > > > will model my data to suit that.
> > > > > 
> > > > > That said, I was experiencing data hotspots with 1  
> > > > > index...filtered/routed aliases(per category) . As the guide suggests that  
> > > > > if there are hotspots then convert that into index, So I am trying to model  
> > > > > each category as index now. The issue is with this approach i have same  
> > > > > document in multiple index (as product can be assoc with multiple  
> > > > > categories).  
> > > > > I am not sure that thats a good approach. So wud appreciate if can get  
> > > > > some advice
> > > > > 
> > > > > On Tuesday, August 27, 2013 9:29:56 AM UTC+5:30, ppearcy wrote:
> > > > > 
> > > > > > I think you need to explain why you don't want to do it the simple  
> > > > > > and straightforward way. The key to using search effectively is to  
> > > > > > denormalize your data, not build some system that does one query well and  
> > > > > > will fall flat outside of that small window.
> > > > > > 
> > > > > > You are trying to get prematurely clever. Don't use routing unless  
> > > > > > there is a guaranteed 1 to 1 mapping between doc to routing value, and even  
> > > > > > then only do it if it makes sense.
> > > > > > 
> > > > > > Best Regards,  
> > > > > > Paul
> > > > > > 
> > > > > > On Monday, August 26, 2013 11:33:29 AM UTC-6, S wrote:
> > > > > > 
> > > > > > > Hi All  
> > > > > > > I am quite confused over a type mapping to fit my model.  
> > > > > > > Main type is "product". A product can be associated with multiple  
> > > > > > > categories. For simplicity say categories are not nested but a product cn  
> > > > > > > have more than 1 category.  
> > > > > > > Now I am thinking to create an index per category and store products  
> > > > > > > routed to that category name.  
> > > > > > > This way if Product#1 is associated with Category#A and Category#B  
> > > > > > > then it will indexed in 2 index (category A and B index). the doc will be  
> > > > > > > exactly same in both.  
> > > > > > > This is okay (i suppose).  
> > > > > > > But if I run any search across all indices and matching this  
> > > > > > > document, then the resultset will contain this Product#1 twice.  
> > > > > > > How can i avoid that?
> > > > > > > 
> > > > > > > ( I dont want to store products in single index with category as  
> > > > > > > array field and corresponding aliases with filtered on category)  
> > > > > > > Do suggest me how this can be done or done better.
> > > > > > > 
> > > > > > > --  
> > > > > > > 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).

--  
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:19am UTC](https://discuss.elastic.co/t/modeling-products-and-category/13330/9 "2017-07-06T02:19:12Z")

</div>


