# Filtering by shard

**URL:** <https://discuss.elastic.co/t/filtering-by-shard/9519>\
**Category:** Elasticsearch\
**Created:** [November 1, 2012, 2:29pm UTC](https://discuss.elastic.co/t/filtering-by-shard/9519 "2012-11-01T14:29:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loic\_Bertron](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loic_bertron/32/1794_2.png) [@Loic\_Bertron](https://discuss.elastic.co/u/Loic_Bertron)\
**Post date:** [November 1, 2012, 2:29pm UTC](https://discuss.elastic.co/t/filtering-by-shard/9519/1 "2012-11-01T14:29:35Z")

</div>

Hello,

I'm trying to resolve a major challenge with ElasticSearch : I have  
documents published since few years, and i'm adding new documents every  
day. But some of documents indexed can't be returned to the client before a  
specified date. But this constraint is only for the docs published during  
the last 15 days max. I dont want to run a query on the entire index to  
check if documents match this constraint but i would like to be able to  
filter results by shards : actually i'm routing my docs during indexing  
based on creation date. Since it's just a boolean filter, i understand that  
it's not altering the score. Is there a way to filter only on a specific  
shard or specific index, so i can run it only on documents from the last 15  
days ?

Thanks a lot.

Loïc

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 1, 2012, 2:49pm UTC](https://discuss.elastic.co/t/filtering-by-shard/9519/2 "2012-11-01T14:49:31Z")

</div>

I cannot think of a way to do it by shard. But if you can create a new  
index every 15 days, you can use indices[http://www.elasticsearch.org/guide/reference/query-dsl/indices-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/indices-query.html)query to add filter for only the last two indices. You can also use filtered  
aliases[http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html)to hide all this complexity from elasticsearch callers.

On Thursday, November 1, 2012 10:29:35 AM UTC-4, Loïc Bertron wrote:

> Hello,
> 
> I'm trying to resolve a major challenge with Elasticsearch : I have  
> documents published since few years, and i'm adding new documents every  
> day. But some of documents indexed can't be returned to the client before a  
> specified date. But this constraint is only for the docs published during  
> the last 15 days max. I dont want to run a query on the entire index to  
> check if documents match this constraint but i would like to be able to  
> filter results by shards : actually i'm routing my docs during indexing  
> based on creation date. Since it's just a boolean filter, i understand that  
> it's not altering the score. Is there a way to filter only on a specific  
> shard or specific index, so i can run it only on documents from the last 15  
> days ?
> 
> Thanks a lot.
> 
> Loïc

--

---

<div class="post-metadata">

**Author:** ![Loic\_Bertron](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loic_bertron/32/1794_2.png) [@Loic\_Bertron](https://discuss.elastic.co/u/Loic_Bertron)\
**Post date:** [November 9, 2012, 2:51pm UTC](https://discuss.elastic.co/t/filtering-by-shard/9519/3 "2012-11-09T14:51:27Z")

</div>

Thanks a lot Igor.

Le jeudi 1 novembre 2012 10:49:31 UTC-4, Igor Motov a écrit :

> I cannot think of a way to do it by shard. But if you can create a new  
> index every 15 days, you can use indices[http://www.elasticsearch.org/guide/reference/query-dsl/indices-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/indices-query.html)query to add filter for only the last two indices. You can also use filtered  
> aliases[http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html](http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html)to hide all this complexity from elasticsearch callers.
> 
> On Thursday, November 1, 2012 10:29:35 AM UTC-4, Loïc Bertron wrote:
> 
> > Hello,
> > 
> > I'm trying to resolve a major challenge with Elasticsearch : I have  
> > documents published since few years, and i'm adding new documents every  
> > day. But some of documents indexed can't be returned to the client before a  
> > specified date. But this constraint is only for the docs published during  
> > the last 15 days max. I dont want to run a query on the entire index to  
> > check if documents match this constraint but i would like to be able to  
> > filter results by shards : actually i'm routing my docs during indexing  
> > based on creation date. Since it's just a boolean filter, i understand that  
> > it's not altering the score. Is there a way to filter only on a specific  
> > shard or specific index, so i can run it only on documents from the last 15  
> > days ?
> > 
> > Thanks a lot.
> > 
> > Loïc

--

---

<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, 3:05am UTC](https://discuss.elastic.co/t/filtering-by-shard/9519/4 "2017-07-06T03:05:08Z")

</div>


