# Excluding documents from a search

**URL:** <https://discuss.elastic.co/t/excluding-documents-from-a-search/230843>\
**Category:** Elasticsearch\
**Created:** [May 3, 2020, 4:16am UTC](https://discuss.elastic.co/t/excluding-documents-from-a-search/230843 "2020-05-03T04:16:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apezzatto](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@apezzatto](https://discuss.elastic.co/u/apezzatto)\
**Post date:** [May 3, 2020, 4:16am UTC](https://discuss.elastic.co/t/excluding-documents-from-a-search/230843/1 "2020-05-03T04:16:39Z")

</div>

Hello all,

I'm a brand new developer using elastic search, and I'm struggling to accomplish what seems to be a simple task: filtering documents that I don't want from my search result result.  
My index consists, among others, a content field and a projectId field. So, I want to simply search for a document which its content posses the keyword "construction" and the projectId must be equal a GUID.  
The thing is, it does not matter how hard I try, I get my desired document at the first position, but then I got others documents that may have "construction" in the content field, but the projectId is not the same I want to filter.

The last version of my code looks like:

```auto
    var response = await _elastic.SearchAsync<ProjectDocumentESModel>(s => s.RequestConfiguration(c => c.DisableDirectStreaming())
    	.Index("*")
    	.Query(q =>
    		q.Terms(p => p.Field(f => f.Content).Terms(keyword))
    		&&
    		q.Bool(b => b
    			.Filter(f => f.Match(m => m.Field(f => f.ProjectId).Query(projectId.ToString())))
    		)
    	)
    );

```

What am I missing here? Please help me.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 3, 2020, 8:06am UTC](https://discuss.elastic.co/t/excluding-documents-from-a-search/230843/2 "2020-05-03T08:06:16Z")

</div>

If you want exact match on the project I’d you should make sure you use a field that is mapped as `keyword `.

---

<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:** [May 31, 2020, 8:06am UTC](https://discuss.elastic.co/t/excluding-documents-from-a-search/230843/3 "2020-05-31T08:06:21Z")

</div>

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