# Why is my term query not working?

**URL:** <https://discuss.elastic.co/t/why-is-my-term-query-not-working/125066>\
**Category:** Elasticsearch\
**Created:** [March 21, 2018, 7:37pm UTC](https://discuss.elastic.co/t/why-is-my-term-query-not-working/125066 "2018-03-21T19:37:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![skilledmonster](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@skilledmonster](https://discuss.elastic.co/u/skilledmonster)\
**Post date:** [March 21, 2018, 7:37pm UTC](https://discuss.elastic.co/t/why-is-my-term-query-not-working/125066/1 "2018-03-21T19:37:45Z")

</div>

Here is my settings file -

```
{
	"settings": {
		"mappings": {
			"default": {
				"properties": {
					"AIRPORT_CODE": {
						"type": "text"
					},
					"PROVINCE_NAME": {
						"type": "text"
					},
					"AIRPORT_NAME": {
						"type": "text"
					},
					"CITY_NAME": {
						"type": "text"
					},
					"TYPE": {
						"type": "keyword"
					},
					"COUNTRY_NAME": {
						"type": "text"
					}
				}
			}
		}
	}
}

```

Here are my sample documents

```
{
  "AIRPORT_CODE": "SQA",
  "PROVINCE_NAME": "California",
  "AIRPORT_NAME": "Santa Ynez Airport",
  "CITY_NAME": "SANTA YNEZ",
  "TYPE": "AIRPORT"
}

{
  "PROVINCE_NAME": "SANTIAGO",
  "CITY_NAME": "SANTIAGO",
  "COUNTRY_NAME": "DOMINICAN REPUBLIC",
  "TYPE": "HOTEL"
}

```

Here is my search -

```
{
	"size": 4,
	"timeout": "2m",
	"query": {
		"bool": {
			"must": [
				{
					"multi_match": {
						"query": "SQA"
					}
				}
			],
			"filter": [
				{
					"term": {
						"TYPE": "AIRPORT"
					}
				}
			]
		}
	},
	"explain": false
}

```

The "TYPE" field has been defined as keyword. But the above query doesn't return anything. If change the "TYPE" value from "AIRPORT" to "airport" (lowercase), I get the results back. What am I doing wrong?

Note # My effort is to get this query working so I can take the advantage of filter cache (node query cache).

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![dunkymole](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dunkymole/32/29105_2.png) [@dunkymole](https://discuss.elastic.co/u/dunkymole)\
**Post date:** [March 21, 2018, 9:08pm UTC](https://discuss.elastic.co/t/why-is-my-term-query-not-working/125066/2 "2018-03-21T21:08:08Z")

</div>

Check the mappings on the server itself. You probably have keyword analyser with lowercase filter. Case must must when querying a field processed by the keyword analyser. Lots of info on Google for this.

---

<div class="post-metadata">

**Author:** ![skilledmonster](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@skilledmonster](https://discuss.elastic.co/u/skilledmonster)\
**Post date:** [March 21, 2018, 9:12pm UTC](https://discuss.elastic.co/t/why-is-my-term-query-not-working/125066/3 "2018-03-21T21:12:10Z")

</div>

I don't think I do. I am running all the above on a new index, you can do the same. Are you saying for keyword analyzer, it has lowercase tokenizer/filter by default?

---

<div class="post-metadata">

**Author:** ![dunkymole](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dunkymole/32/29105_2.png) [@dunkymole](https://discuss.elastic.co/u/dunkymole)\
**Post date:** [March 21, 2018, 9:30pm UTC](https://discuss.elastic.co/t/why-is-my-term-query-not-working/125066/4 "2018-03-21T21:30:21Z")

</div>

I am suggesting that's what you find out by checking on the server. I don't  
know off the top of my head.

---

<div class="post-metadata">

**Author:** ![skilledmonster](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@skilledmonster](https://discuss.elastic.co/u/skilledmonster)\
**Post date:** [March 21, 2018, 9:59pm UTC](https://discuss.elastic.co/t/why-is-my-term-query-not-working/125066/5 "2018-03-21T21:59:56Z")

</div>

When do this -  
POST \_analyze  
{  
"tokenizer": "keyword",  
"text": "AIRPORT"  
}

I get back -  
{  
"tokens": [  
{  
"token": "AIRPORT",  
"start\_offset": 0,  
"end\_offset": 7,  
"type": "word",  
"position": 0  
}  
]  
}

So by default it doesn't convert lower case. Which is what I have as well.

---

<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:** [April 18, 2018, 10:00pm UTC](https://discuss.elastic.co/t/why-is-my-term-query-not-working/125066/6 "2018-04-18T22:00:08Z")

</div>

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