# Excluding result from the search

**URL:** https://discuss.elastic.co/t/excluding-result-from-the-search/188932
**Category:** Elasticsearch
**Created:** [July 4, 2019, 2:38pm UTC](https://discuss.elastic.co/t/excluding-result-from-the-search/188932 "2019-07-04T14:38:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![schneider](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schneider](https://discuss.elastic.co/u/schneider)
#### Post date: [July 4, 2019, 2:38pm UTC](https://discuss.elastic.co/t/excluding-result-from-the-search/188932/1 "2019-07-04T14:38:49Z")

</div>

I want to that some terns are excluded from the search, this is de cod:

```
GET /imsva_message/_search 
{ 
"size": 0,
"aggs" : { 
    "aggdata" : { 
        "filter": { 
          "range": {
            "data1": {
              "from": "now-15m",
              "to": "now"
            }
          }
        },
        "aggs" : { 
          "aggremetente" : { 
            "terms" : { 
              "field" : "remetente.keyword",
              "min_doc_count":50  
            }
          }
        } 
    } 
} 
}

```

and this is the result:

```
{
"took" : 227,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3188121,
"max_score" : 0.0,
"hits" : []
},
"aggregations" : {
"aggdata" : {
  "doc_count" : 1254,
  "aggremetente" : {
    "doc_count_error_upper_bound" : 5,
    "sum_other_doc_count" : 309,
    "buckets" : [
      {
        "key" : "xxx@xxx.xxx.xxx",
        "doc_count" : 464
      },
      {
        "key" : "yyy.yyy@yyy.yyy.yyy",
        "doc_count" : 159
      },
      {
        "key" : "zzz@zzz.zzz.zzz",
        "doc_count" : 50
      }
    ]
  }
}
}
}

```

how do I do for the result to be:

```
{
"took" : 227,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3188121,
"max_score" : 0.0,
"hits" : []
},
"aggregations" : {
"aggdata" : {
  "doc_count" : 1254,
  "aggremetente" : {
    "doc_count_error_upper_bound" : 5,
    "sum_other_doc_count" : 309,
    "buckets" : [
      {
        "key" : "yyy.yyy@yyy.yyy.yyy",
        "doc_count" : 159
      },
      {
        "key" : "zzz@zzz.zzz.zzz",
        "doc_count" : 50
      }
    ]
  }
}
}
}

```

removing the term :

```
{
        "key" : "xxx@xxx.xxx.xxx",
        "doc_count" : 464
}

```

of search, or removing any other terms for the search?

---

<div class="post-metadata">

### Author: ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)
#### Post date: [July 4, 2019, 2:51pm UTC](https://discuss.elastic.co/t/excluding-result-from-the-search/188932/2 "2019-07-04T14:51:29Z")

</div>

Hi @schneider,

If you want to exclude all "remetente" value that are not yyy.yyy@yyy you can use a term query:  
[https://www.elastic.co/guide/en/elasticsearch/reference/7.2/query-dsl-term-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/query-dsl-term-query.html)  
Where your term will be equal to yyyy....

Or if you want to exclude some terms like xxx or zzzz you can use the terms query encapsulated inside a bool must not.

[https://www.elastic.co/guide/en/elasticsearch/reference/7.2/query-dsl-terms-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/query-dsl-terms-query.html)  
[https://www.elastic.co/guide/en/elasticsearch/reference/7.2/query-dsl-bool-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/query-dsl-bool-query.html)

---

<div class="post-metadata">

### Author: ![schneider](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schneider](https://discuss.elastic.co/u/schneider)
#### Post date: [July 4, 2019, 3:29pm UTC](https://discuss.elastic.co/t/excluding-result-from-the-search/188932/3 "2019-07-04T15:29:03Z")

</div>

Thx gabriel

---

<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: [August 1, 2019, 3:29pm UTC](https://discuss.elastic.co/t/excluding-result-from-the-search/188932/4 "2019-08-01T15:29:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
