# Routing by diferent fields

**URL:** <https://discuss.elastic.co/t/routing-by-diferent-fields/13794>\
**Category:** Elasticsearch\
**Created:** [September 27, 2013, 9:45pm UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794 "2013-09-27T21:45:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![silvina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silvina/32/44096_2.png) [@silvina](https://discuss.elastic.co/u/silvina)\
**Post date:** [September 27, 2013, 9:45pm UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794/1 "2013-09-27T21:45:15Z")

</div>

Hi,  
Is it possible search data with diferent routing field in the same index?.  
For example, I would like make search and set the routing by person\_id and  
other search with item\_id.  
index1/search?routing=person\_id  
index1/search?routing=item\_id

Do I need create another index?  
Thanks,  
Silvina.

--  
(\__/)  
(='.'=)  
(")_(")

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 28, 2013, 12:24am UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794/2 "2013-09-28T00:24:53Z")

</div>

Are you looking for index/\_search?routing=person\_id,item\_id  
See: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/)

It could perform search on two shards (or one if the two keys goes to the same shard).

Does it help?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 28 sept. 2013 à 00:45, silvina [svlucero@gmail.com](mailto:svlucero@gmail.com) a écrit :

> Hi,  
> Is it possible search data with diferent routing field in the same index?. For example, I would like make search and set the routing by person\_id and other search with item\_id.  
> index1/search?routing=person\_id  
> index1/search?routing=item\_id
> 
> Do I need create another index?  
> Thanks,  
> Silvina.
> 
> --  
> (\__/)  
> (='.'=)  
> (")_(")
> 
> --  
> 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:** ![silvina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silvina/32/44096_2.png) [@silvina](https://discuss.elastic.co/u/silvina)\
**Post date:** [September 30, 2013, 4:31pm UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794/3 "2013-09-30T16:31:26Z")

</div>

Any idea about that?

On Fri, Sep 27, 2013 at 6:45 PM, silvina [svlucero@gmail.com](mailto:svlucero@gmail.com) wrote:

> Hi,  
> Is it possible search data with diferent routing field in the same  
> index?. For example, I would like make search and set the routing by  
> person\_id and other search with item\_id.  
> index1/search?routing=person\_id  
> index1/search?routing=item\_id
> 
> Do I need create another index?  
> Thanks,  
> Silvina.
> 
> --  
> (\__/)  
> (='.'=)  
> (")_(")

--  
(\__/)  
(='.'=)  
(")_(")

--  
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:** ![silvina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silvina/32/44096_2.png) [@silvina](https://discuss.elastic.co/u/silvina)\
**Post date:** [October 2, 2013, 7:01pm UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794/4 "2013-10-02T19:01:11Z")

</div>

Thanks David,  
No, I need make diferents search, sometimes routing by person\_id and  
sometimes by item\_id on the same index when the shards where index by  
item\_id. It is possible? Can I search by different fields?

El viernes, 27 de septiembre de 2013 21:24:53 UTC-3, David Pilato escribió:

> Are you looking for index/\_search?routing=person\_id,item\_id  
> See: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/)
> 
> It could perform search on two shards (or one if the two keys goes to the  
> same shard).
> 
> Does it help?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 28 sept. 2013 à 00:45, silvina \<[svlu...@gmail.com](mailto:svlu...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi,  
> Is it possible search data with diferent routing field in the same  
> index?. For example, I would like make search and set the routing by  
> person\_id and other search with item\_id.  
> index1/search?routing=person\_id  
> index1/search?routing=item\_id
> 
> Do I need create another index?  
> Thanks,  
> Silvina.
> 
> --  
> (\__/)  
> (='.'=)  
> (")_(")
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> 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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 2, 2013, 7:38pm UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794/5 "2013-10-02T19:38:55Z")

</div>

Sorry. I don't understand.  
May be you could illustrate with a concrete example?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 2 oct. 2013 à 21:01, anivlis [svlucero@gmail.com](mailto:svlucero@gmail.com) a écrit :

> Thanks David,  
> No, I need make diferents search, sometimes routing by person\_id and sometimes by item\_id on the same index when the shards where index by item\_id. It is possible? Can I search by different fields?
> 
> El viernes, 27 de septiembre de 2013 21:24:53 UTC-3, David Pilato escribió:
> 
> > Are you looking for index/\_search?routing=person\_id,item\_id  
> > See: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/)
> > 
> > It could perform search on two shards (or one if the two keys goes to the same shard).
> > 
> > Does it help?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 28 sept. 2013 à 00:45, silvina [svlu...@gmail.com](mailto:svlu...@gmail.com) a écrit :
> > 
> > > Hi,  
> > > Is it possible search data with diferent routing field in the same index?. For example, I would like make search and set the routing by person\_id and other search with item\_id.  
> > > index1/search?routing=person\_id  
> > > index1/search?routing=item\_id
> > > 
> > > Do I need create another index?  
> > > Thanks,  
> > > Silvina.
> > > 
> > > --  
> > > (\__/)  
> > > (='.'=)  
> > > (")_(")
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@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).

--  
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:** ![silvina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silvina/32/44096_2.png) [@silvina](https://discuss.elastic.co/u/silvina)\
**Post date:** [October 2, 2013, 8:52pm UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794/6 "2013-10-02T20:52:29Z")

</div>

I have a elasticsearch with 16 shard and 2 replications. I index data with  
routing:

```
            "_routing" : {
                "required" : true,
                "path" : "item_id"
        }

```

But when I'm looking for documents routed by a different field (person\_id)  
the result is a part of the total result. For example, I have 100 documents  
with person\_id=1 but only 10 are in the result set. I think this happen  
because the data is not in the same shard so when elasticsearch is routing  
by a person\_id then only one shard is visited and the rest is ignored.  
How can be sure that when routing by different field the result set is  
complete?

El miércoles, 2 de octubre de 2013 16:38:55 UTC-3, David Pilato escribió:

> Sorry. I don't understand.  
> May be you could illustrate with a concrete example?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 2 oct. 2013 à 21:01, anivlis \<[svlu...@gmail.com](mailto:svlu...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Thanks David,  
> No, I need make diferents search, sometimes routing by person\_id and  
> sometimes by item\_id on the same index when the shards where index by  
> item\_id. It is possible? Can I search by different fields?
> 
> El viernes, 27 de septiembre de 2013 21:24:53 UTC-3, David Pilato escribió:
> 
> > Are you looking for index/\_search?routing=person\_id,item\_id  
> > See: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/)
> > 
> > It could perform search on two shards (or one if the two keys goes to the  
> > same shard).
> > 
> > Does it help?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 28 sept. 2013 à 00:45, silvina [svlu...@gmail.com](mailto:svlu...@gmail.com) a écrit :
> > 
> > Hi,  
> > Is it possible search data with diferent routing field in the same  
> > index?. For example, I would like make search and set the routing by  
> > person\_id and other search with item\_id.  
> > index1/search?routing=person\_id  
> > index1/search?routing=item\_id
> > 
> > Do I need create another index?  
> > Thanks,  
> > Silvina.
> > 
> > --  
> > (\__/)  
> > (='.'=)  
> > (")_(")
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > 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:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 2, 2013, 9:12pm UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794/7 "2013-10-02T21:12:30Z")

</div>

If you index with routing, you place a doc by a fixed key into a shard.  
Think of the distribution as a partition pattern that is immutable. If you  
use another key for the distribution and not the one you used while  
indexing, you will clearly not be able to find all documents. It's like a  
door with a key - only one key fits into the lock.

Routing is not filtering. Maybe you just want to filter docs by different  
fields.

Jörg

--  
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:** ![silvina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silvina/32/44096_2.png) [@silvina](https://discuss.elastic.co/u/silvina)\
**Post date:** [October 2, 2013, 10:27pm UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794/8 "2013-10-02T22:27:33Z")

</div>

Thanks jorg,  
I don't want scan all shards when I make a search. In that case, which is  
the best solution? Maybe I need create another index with different  
routing.

El miércoles, 2 de octubre de 2013 18:12:30 UTC-3, Jörg Prante escribió:

> If you index with routing, you place a doc by a fixed key into a shard.  
> Think of the distribution as a partition pattern that is immutable. If you  
> use another key for the distribution and not the one you used while  
> indexing, you will clearly not be able to find all documents. It's like a  
> door with a key - only one key fits into the lock.
> 
> Routing is not filtering. Maybe you just want to filter docs by different  
> fields.
> 
> Jörg

--  
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:13am UTC](https://discuss.elastic.co/t/routing-by-diferent-fields/13794/9 "2017-07-06T02:13:58Z")

</div>


