# Term Query to Exclude Others

**URL:** <https://discuss.elastic.co/t/term-query-to-exclude-others/129244>\
**Category:** Elasticsearch\
**Created:** [April 24, 2018, 7:29am UTC](https://discuss.elastic.co/t/term-query-to-exclude-others/129244 "2018-04-24T07:29:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NewHere](https://avatars.discourse-cdn.com/v4/letter/n/5e9695/32.png) [@NewHere](https://discuss.elastic.co/u/NewHere)\
**Post date:** [April 24, 2018, 7:29am UTC](https://discuss.elastic.co/t/term-query-to-exclude-others/129244/1 "2018-04-24T07:29:43Z")

</div>

Hi this may seem too elementary but I am also new to elasticsearch, so please bare with me. Say I have two documents, one with "name" : "ABC Company" and one with "name" : "ABC". Setting for the "name" field is of "text" type with Standard analyser.

When doing a Term query like below:

```
{
    "query": {
        "bool": {
            "must": [{
                "term": {
                    "name": "abc"
                }
            },
            {
                "term": {
                    "name": "company"
                }
            }]
        }
    }
}

```

I can get exclusively the "ABC Company" document.  
But doing this Term query:

```
{
    "query": {
        "bool": {
            "must": [{
                "term": {
                    "name": "abc"
                }
            }]
        }
    }
}

```

would return both documents "ABC Company" and "ABC".

How should I do the query so that I get just "ABC" to return in the second query without changing the indexing settings (e.g. adding extra keyword fields).

---

<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 22, 2018, 7:29am UTC](https://discuss.elastic.co/t/term-query-to-exclude-others/129244/2 "2018-05-22T07:29:52Z")

</div>

Closed on May 22, 2018, 7:29am UTC

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