# Term query confusion

**URL:** <https://discuss.elastic.co/t/term-query-confusion/3155>\
**Category:** Elasticsearch\
**Created:** [July 26, 2010, 10:47pm UTC](https://discuss.elastic.co/t/term-query-confusion/3155 "2010-07-26T22:47:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Jensen\_2](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@David\_Jensen\_2](https://discuss.elastic.co/u/David_Jensen_2)\
**Post date:** [July 26, 2010, 10:47pm UTC](https://discuss.elastic.co/t/term-query-confusion/3155/1 "2010-07-26T22:47:24Z")

</div>

I ran a term query and didn't get the expected results. So I read  
through some of the past conversations, looked up Lucene TermQuery and  
I'm still a little confused about what's going wrong. It seems what  
I'm doing should work.

ElasticSearch version: 0.8.0

Sample document being indexed:  
{  
"name": "David Jensen",  
"validationDateString": "2010-07-26T11:09:10",  
"title": "Engineering",  
"companyName": "Spoke Software, Inc.",  
"urls": ["[http://www.spoke.com](http://www.spoke.com)", "[http://www.spokepay.com](http://www.spokepay.com)", "http://  
[www.spokesoftware.com/](http://www.spokesoftware.com/)"],  
"sicCodes": ["7371","8742","7374"],  
"cities": ["San Mateo"],  
"states": ["CA"],  
"businessSummary": "Business contacts and networking..."  
}

The following query returns zero results:  
curl -XPOST '[http://localhost:9200/spokeprofile/person/\_search](http://localhost:9200/spokeprofile/person/_search)' -d  
'{ "query":{ "term":{"name": "Jensen"} } }'

The following queries return exactly 4011 results:  
curl -XPOST '[http://localhost:9200/spokeprofile/person/\_search](http://localhost:9200/spokeprofile/person/_search)' -d  
'{ "query":{ "field":{"name": "Jensen"} } }'  
curl -XPOST '[http://localhost:9200/spokeprofile/person/\_search](http://localhost:9200/spokeprofile/person/_search)' -d  
'{ "query":{ "query\_string":{"default\_field":"name",  
"query":"Jensen"} } }'  
curl -XPOST '[http://localhost:9200/spokeprofile/person/\_search](http://localhost:9200/spokeprofile/person/_search)?  
q=name:Jensen'

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [July 27, 2010, 1:59am UTC](https://discuss.elastic.co/t/term-query-confusion/3155/2 "2010-07-27T01:59:31Z")

</div>

The inputs to a term query are not analyzed, implying that it must  
match the exact term as stored in the index.

What analysis happens to the 'name' field on the index side?

If you used a non-lowercasing white space analyzer that should match.  
I assume your analyzer is lower casing, so searching on term 'jenson'  
should work.

Field queries are analyzed, which is why that works.

On Jul 26, 4:47 pm, David Jensen [djense...@gmail.com](mailto:djense...@gmail.com) wrote:

> I ran a term query and didn't get the expected results. So I read  
> through some of the past conversations, looked up Lucene TermQuery and  
> I'm still a little confused about what's going wrong. It seems what  
> I'm doing should work.
> 
> Elasticsearch version: 0.8.0
> 
> Sample document being indexed:  
> {  
> "name": "David Jensen",  
> "validationDateString": "2010-07-26T11:09:10",  
> "title": "Engineering",  
> "companyName": "Spoke Software, Inc.",  
> "urls": ["[http://www.spoke.com](http://www.spoke.com)", "[http://www.spokepay.com](http://www.spokepay.com)", "[http://www.spokesoftware.com/](http://www.spokesoftware.com/)"],  
> "sicCodes": ["7371","8742","7374"],  
> "cities": ["San Mateo"],  
> "states": ["CA"],  
> "businessSummary": "Business contacts and networking..."
> 
> }
> 
> The following query returns zero results:  
> curl -XPOST '[http://localhost:9200/spokeprofile/person/\_search'-d](http://localhost:9200/spokeprofile/person/_search'-d)  
> '{ "query":{ "term":{"name": "Jensen"} } }'
> 
> The following queries return exactly 4011 results:  
> curl -XPOST '[http://localhost:9200/spokeprofile/person/\_search'-d](http://localhost:9200/spokeprofile/person/_search'-d)  
> '{ "query":{ "field":{"name": "Jensen"} } }'  
> curl -XPOST '[http://localhost:9200/spokeprofile/person/\_search'-d](http://localhost:9200/spokeprofile/person/_search'-d)  
> '{ "query":{ "query\_string":{"default\_field":"name",  
> "query":"Jensen"} } }'  
> curl -XPOST '[http://localhost:9200/spokeprofile/person/\_search](http://localhost:9200/spokeprofile/person/_search)?  
> q=name:Jensen'

---

<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:** [July 6, 2017, 4:21am UTC](https://discuss.elastic.co/t/term-query-confusion/3155/3 "2017-07-06T04:21:34Z")

</div>


