# Term query wrong behaviour?

**URL:** <https://discuss.elastic.co/t/term-query-wrong-behaviour/287530>\
**Category:** Elasticsearch\
**Created:** [October 25, 2021, 4:33am UTC](https://discuss.elastic.co/t/term-query-wrong-behaviour/287530 "2021-10-25T04:33:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [October 25, 2021, 4:33am UTC](https://discuss.elastic.co/t/term-query-wrong-behaviour/287530/1 "2021-10-25T04:33:01Z")

</div>

Hi, according to the documentation a term query search for the exact match. but when I do the below search I get results

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/a/0a09f8f336e4e5115112ef5538d18ea3892ef329.png)  
and when I look for the exact match in uppercase I dont get any results  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/6/2636e1e350931b7b7a69b3158c96c2e607faa656.png)

This should not happen, or I didn't understand the documentation?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 25, 2021, 4:34am UTC](https://discuss.elastic.co/t/term-query-wrong-behaviour/287530/2 "2021-10-25T04:34:35Z")

</div>

Please don't post pictures of text or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them 🙂

It sounds like this will come down to how the field is mapped, so can you check that?

---

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [October 25, 2021, 4:39am UTC](https://discuss.elastic.co/t/term-query-wrong-behaviour/287530/3 "2021-10-25T04:39:00Z")

</div>

Hi, this is the mapping of the speaker field

```auto
{
  "shakespeare" : {
    "mappings" : {
      "speaker" : {
        "full_name" : "speaker",
        "mapping" : {
          "speaker" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [October 25, 2021, 7:09am UTC](https://discuss.elastic.co/t/term-query-wrong-behaviour/287530/4 "2021-10-25T07:09:43Z")

</div>

> [@ElasticLiver](#):
>
> according to the documentation a term query search for the exact match.

It is an exact match with what is in the index, not what was in your original JSON. In your ‘text’ field the content has been lowercased.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [October 25, 2021, 3:11pm UTC](https://discuss.elastic.co/t/term-query-wrong-behaviour/287530/5 "2021-10-25T15:11:12Z")

</div>

Your mapping does not look correct to me.

Assuming it is correct you are searching against the `text` field speaker not `keyword` fields `speaker.keyword` for an exact match... text field will ignore cas

Run these 1 by one below and observe the difference you will sett

```auto
PUT discuss/
{
  "mappings": {
    "properties": {
      "speaker": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}

POST discuss/_doc
{
  "speaker" : "DOYLE"
}

POST discuss/_doc
{
  "speaker" : "doyle"
}

GET discuss/_search
{
  "query": {
    "term": {
      "speaker": {
        "value": "doyle"
      }
    }
  }
}

GET discuss/_search
{
  "query": {
    "term": {
      "speaker.keyword": {
        "value": "doyle"
      }
    }
  }
}

```

---

<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:** [November 22, 2021, 3:11pm UTC](https://discuss.elastic.co/t/term-query-wrong-behaviour/287530/6 "2021-11-22T15:11:13Z")

</div>

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