# Removing docs from search results

**URL:** <https://discuss.elastic.co/t/removing-docs-from-search-results/20001>\
**Category:** Elasticsearch\
**Created:** [September 29, 2014, 6:04pm UTC](https://discuss.elastic.co/t/removing-docs-from-search-results/20001 "2014-09-29T18:04:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mromagnoli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mromagnoli/32/839_2.png) [@mromagnoli](https://discuss.elastic.co/u/mromagnoli)\
**Post date:** [September 29, 2014, 6:04pm UTC](https://discuss.elastic.co/t/removing-docs-from-search-results/20001/1 "2014-09-29T18:04:29Z")

</div>

Hi everyone,

I am having the next issue: I want to remove some docs from the results  
based in conditions. I think this is the behavior that 'filters' have. The  
problem is that couldn't get with the correct solution.

Example:

If I have an index with shops like :

{  
"Shop": {  
"name": 'Bakery My Bread'  
}  
},  
{  
"Shop": {  
"name": 'Butcher Jason'  
}  
},  
{  
"Shop": {  
"name": 'Sex Shop Toys'  
}  
},  
{  
"Shop": {  
"name": 'Video Shop DVD'  
}  
},

What I did was to add 'sex' to the stopwords file so if someone search  
that word, it is discarded. This works fine at search time for that word  
because since it is a single token, none results are retrieved. The problem  
occurs when someone search something like 'shop', and, in this case, 2  
results are retrieved, and one of them is 'Sex Shop Toys', something I  
don't want to retrieve.

Should I use some filter specifically? I tried with bool filter, regexp and  
not filter but those undesirable results still being brought.

Thanks in advance

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [September 29, 2014, 6:33pm UTC](https://discuss.elastic.co/t/removing-docs-from-search-results/20001/2 "2014-09-29T18:33:39Z")

</div>

You have to use a technique known as anti-phrasing. "not" filters work well.

In your case of a "shop" query, something like

{  
"query" : {  
"filtered" : {  
"query" : {  
"simple\_query\_string" : {  
"query" : "shop",  
"default\_operator": "and"  
}  
},  
"filter" : {  
"not" : {  
"\_cache": true,  
"filter" : {  
"query": {  
"match" : {  
"\_all" : "sex"  
}  
}  
}  
}  
}  
}  
}  
}

Other example with query\_string:

> <https://gist.github.com/jprante/6816555>

Jörg

On Mon, Sep 29, 2014 at 8:04 PM, @mromagnoli [marce.romagnoli@gmail.com](mailto:marce.romagnoli@gmail.com)  
wrote:

> Hi everyone,
> 
> I am having the next issue: I want to remove some docs from the results  
> based in conditions. I think this is the behavior that 'filters' have. The  
> problem is that couldn't get with the correct solution.
> 
> Example:
> 
> If I have an index with shops like :
> 
> {  
> "Shop": {  
> "name": 'Bakery My Bread'  
> }  
> },  
> {  
> "Shop": {  
> "name": 'Butcher Jason'  
> }  
> },  
> {  
> "Shop": {  
> "name": 'Sex Shop Toys'  
> }  
> },  
> {  
> "Shop": {  
> "name": 'Video Shop DVD'  
> }  
> },
> 
> What I did was to add 'sex' to the stopwords file so if someone search  
> that word, it is discarded. This works fine at search time for that word  
> because since it is a single token, none results are retrieved. The problem  
> occurs when someone search something like 'shop', and, in this case, 2  
> results are retrieved, and one of them is 'Sex Shop Toys', something I  
> don't want to retrieve.
> 
> Should I use some filter specifically? I tried with bool filter, regexp  
> and not filter but those undesirable results still being brought.
> 
> Thanks in advance
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHkOd--PExgEcZ5qH-fgXUBBD9h4EL\_HS%3D-CZJJxqAQ7g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHkOd--PExgEcZ5qH-fgXUBBD9h4EL_HS%3D-CZJJxqAQ7g%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![mromagnoli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mromagnoli/32/839_2.png) [@mromagnoli](https://discuss.elastic.co/u/mromagnoli)\
**Post date:** [September 29, 2014, 7:13pm UTC](https://discuss.elastic.co/t/removing-docs-from-search-results/20001/3 "2014-09-29T19:13:18Z")

</div>

Jörg, worked perfectly with my problem!!!

Thank you very much for your response and your time.

Marcelo

On Monday, September 29, 2014 3:33:49 PM UTC-3, Jörg Prante wrote:

> You have to use a technique known as anti-phrasing. "not" filters work  
> well.
> 
> In your case of a "shop" query, something like
> 
> {  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "simple\_query\_string" : {  
> "query" : "shop",  
> "default\_operator": "and"  
> }  
> },  
> "filter" : {  
> "not" : {  
> "\_cache": true,  
> "filter" : {  
> "query": {  
> "match" : {  
> "\_all" : "sex"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Other example with query\_string:
> 
> [Anti-phrasing · GitHub](https://gist.github.com/jprante/6816555)
> 
> Jörg
> 
> On Mon, Sep 29, 2014 at 8:04 PM, @mromagnoli \<[marce.r...@gmail.com](mailto:marce.r...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi everyone,
> > 
> > I am having the next issue: I want to remove some docs from the results  
> > based in conditions. I think this is the behavior that 'filters' have. The  
> > problem is that couldn't get with the correct solution.
> > 
> > Example:
> > 
> > If I have an index with shops like :
> > 
> > {  
> > "Shop": {  
> > "name": 'Bakery My Bread'  
> > }  
> > },  
> > {  
> > "Shop": {  
> > "name": 'Butcher Jason'  
> > }  
> > },  
> > {  
> > "Shop": {  
> > "name": 'Sex Shop Toys'  
> > }  
> > },  
> > {  
> > "Shop": {  
> > "name": 'Video Shop DVD'  
> > }  
> > },
> > 
> > What I did was to add 'sex' to the stopwords file so if someone search  
> > that word, it is discarded. This works fine at search time for that word  
> > because since it is a single token, none results are retrieved. The problem  
> > occurs when someone search something like 'shop', and, in this case, 2  
> > results are retrieved, and one of them is 'Sex Shop Toys', something I  
> > don't want to retrieve.
> > 
> > Should I use some filter specifically? I tried with bool filter, regexp  
> > and not filter but those undesirable results still being brought.
> > 
> > Thanks in advance
> > 
> > --  
> > 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:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3218ec76-7082-4cd1-a44b-11b450f86669%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/915a89b2-968a-45a2-939b-d59375f9243d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/915a89b2-968a-45a2-939b-d59375f9243d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:59am UTC](https://discuss.elastic.co/t/removing-docs-from-search-results/20001/4 "2017-07-06T00:59:15Z")

</div>

Closed on July 6, 2017, 12:59am UTC


