# What I am wrong with search using term query?

**URL:** <https://discuss.elastic.co/t/what-i-am-wrong-with-search-using-term-query/51131>\
**Category:** Elasticsearch\
**Created:** [May 27, 2016, 8:30am UTC](https://discuss.elastic.co/t/what-i-am-wrong-with-search-using-term-query/51131 "2016-05-27T08:30:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![morning-color](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@morning-color](https://discuss.elastic.co/u/morning-color)\
**Post date:** [May 27, 2016, 8:30am UTC](https://discuss.elastic.co/t/what-i-am-wrong-with-search-using-term-query/51131/1 "2016-05-27T08:30:30Z")

</div>

hi，guys. I got a problem when i am using search mothed with term query.  
I write two similar curl commands， the only different part is the query aims at different fields in the same document. But one is success, the other is failed. I can't figure out where I am wrong, so please help me. Many Thanks.

Here are the commands and their results:  
**The success command：**  
$ curl -XGET '[http://localhost:9200/cmongo\_statistics/cmongo\_cluster\_info/\_search?pretty](http://localhost:9200/cmongo_statistics/cmongo_cluster_info/_search?pretty)' -d '{"query":{"term":{"region\_id":1}}}'0

**The right result：**

{  
"took" : 8,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 76,  
"max\_score" : 0.9780211,  
"hits" : [ {  
"\_index" : "cmongo\_statistics",  
"\_type" : "cmongo\_cluster\_info",  
"\_id" : "AVTtMUejStKgUadx78sX",  
"\_score" : 0.9780211,  
"\_source" : {  
"region\_id" : 1,  
"cluster\_id" : "cmgo-79rjj8o3",  
"all\_storage" : 30720,  
"timestamp" : 1464268310  
}  
}, { ...

* * *

**The wrong command：**  
curl -XGET '[http://localhost:9200/cmongo\_statistics/cmongo\_cluster\_info/\_search?pretty](http://localhost:9200/cmongo_statistics/cmongo_cluster_info/_search?pretty)' -d '{"query":{"term":{"cluster\_id" : "cmgo-79rjj8o3"}}}'

**The wrong result：**  
{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

* * *

**command contrast**  
the success one：  
curl -XGET '[http://localhost:9200/cmongo\_statistics/cmongo\_cluster\_info/\_search?pretty](http://localhost:9200/cmongo_statistics/cmongo_cluster_info/_search?pretty)' -d '{"query":{"term":{"region\_id":1}}}'0

the failed one：  
curl -XGET '[http://localhost:9200/cmongo\_statistics/cmongo\_cluster\_info/\_search?pretty](http://localhost:9200/cmongo_statistics/cmongo_cluster_info/_search?pretty)' -d '{"query":{"term":{"cluster\_id" : "cmgo-79rjj8o3"}}}'

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 27, 2016, 8:43am UTC](https://discuss.elastic.co/t/what-i-am-wrong-with-search-using-term-query/51131/2 "2016-05-27T08:43:49Z")

</div>

Please format your code.

Term queries are not analyzed. So you are comparing with what exist in the inverted index.

Probably your text `cmgo-79rjj8o3` has been analyzed and indexed as `cmgo` `79rjj8o3`.

That's the reason it does not match.

You can use a match query instead or change the analyzer for your field to be not\_analyzed. `index: not_analyzed`

---

<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:48pm UTC](https://discuss.elastic.co/t/what-i-am-wrong-with-search-using-term-query/51131/3 "2017-07-05T22:48:34Z")

</div>


