# Term vs match confusion

**URL:** <https://discuss.elastic.co/t/term-vs-match-confusion/50018>\
**Category:** Elasticsearch\
**Created:** [May 13, 2016, 6:00pm UTC](https://discuss.elastic.co/t/term-vs-match-confusion/50018 "2016-05-13T18:00:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zetian](https://avatars.discourse-cdn.com/v4/letter/z/f14d63/32.png) [@zetian](https://discuss.elastic.co/u/zetian)\
**Post date:** [May 13, 2016, 6:00pm UTC](https://discuss.elastic.co/t/term-vs-match-confusion/50018/1 "2016-05-13T18:00:23Z")

</div>

I have code that dynamically generates queries for a web service using queryBuilder, but it doesn't seem to work for a specific field / query type. I have exported the resulting queries as string to try and understand what is going wrong but I cannot see the error.

This query does not work:  
{"bool" : {  
"filter" : [ {  
"range" : {  
"INVOICE\_DATE" : {  
"from" : 1447438997610,  
"to" : 1463160197610,  
"include\_lower" : true,  
"include\_upper" : true  
}}},  
{"term" : {"BILL\_TO\_NUMBER" : 100551}  
}, {term" : {"CUSTOMER\_PO\_NUMBER" : "Gawin" }} ]}}

This does:  
{"bool" : {  
"filter" : [ {  
"range" : {  
"INVOICE\_DATE" : {  
"from" : 1447438997610,  
"to" : 1463160197610,  
"include\_lower" : true,  
"include\_upper" : true  
}}},  
{"term" : {"BILL\_TO\_NUMBER" : 100551}},  
{"term" : {"ORDER\_NUMBER" : 1349929}} ]}}

The matching document for both queries is the same:  
{ "\_index": "cps\_documents",  
"\_type": "invoice",  
"\_id": "819055",  
"\_score": null,  
"fields": {  
"CUSTOMER\_PO\_NUMBER": ["Gawin"],  
"DOCID": [819055],  
"INVOICE\_DATE": [1456207200000],  
"INVOICE\_NUMBER": [1982323],  
"ORDER\_NUMBER": [1349929],  
"SHIP\_TO\_NUMBER": [100552],  
"DATESTORED": [1456276439000],  
"BILL\_TO\_NAME": ["Action Heating & Air Conditioning"],  
"BILL\_TO\_NUMBER": [100551]}

I thought maybe the mapping was different than I expected for CUSTOMER\_PO\_NUMBER  
but it is using the standard analyzer and defined as a string...

"CUSTOMER\_PO\_NUMBER": {  
"type": "string"  
},

The following query with a slightly different syntax also works fine:  
{  
"bool": {  
"must": [  
{"match": {  
"BILL\_TO\_NUMBER": "100551"  
}},  
{"match": {  
"CUSTOMER\_PO\_NUMBER": "Gawin"  
}},  
{"range": {  
"INVOICE\_DATE": {  
"from": 1447430782568,  
"to": 1463151982568  
}  
}}  
]  
}}

Can you see what I am missing?

---

<div class="post-metadata">

**Author:** ![zetian](https://avatars.discourse-cdn.com/v4/letter/z/f14d63/32.png) [@zetian](https://discuss.elastic.co/u/zetian)\
**Post date:** [May 13, 2016, 7:40pm UTC](https://discuss.elastic.co/t/term-vs-match-confusion/50018/2 "2016-05-13T19:40:03Z")

</div>

It turns out that a 'match' query worked fine for 'Gawin' but not a 'term query. I figured out that a 'term query' searches specifically for what is in the index where the 'match query' uses the standard analyzer.

If I reformat the query with a lower case 'g' then the term query is successful.

---

<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 5, 2017, 10:51pm UTC](https://discuss.elastic.co/t/term-vs-match-confusion/50018/3 "2017-07-05T22:51:30Z")

</div>


