# Term query question

**URL:** <https://discuss.elastic.co/t/term-query-question/11229>\
**Category:** Elasticsearch\
**Created:** [March 20, 2013, 9:49pm UTC](https://discuss.elastic.co/t/term-query-question/11229 "2013-03-20T21:49:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fish\_Tastic](https://avatars.discourse-cdn.com/v4/letter/f/4bbf92/32.png) [@Fish\_Tastic](https://discuss.elastic.co/u/Fish_Tastic)\
**Post date:** [March 20, 2013, 9:49pm UTC](https://discuss.elastic.co/t/term-query-question/11229/1 "2013-03-20T21:49:55Z")

</div>

I created some random data to test search.

When it do I match query, it works fine.  
curl -XGET  
'[http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_search?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_search?pretty=true)'  
-d '{query:{"match": {"field1":"PITU"}}}'  
{  
"took" : 3,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 10.21034,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "test",  
"\_id" : "78116",  
"\_score" : 10.21034, "\_source" : {"id":78115,"field1":"_PITU_","field2":"DKBV  
GOAT","field3":"JXIX FPOZ WZIV","field4":"GQWZ AFHU VMJF  
AENE","field5":"BFEJ BEEX CHNM VCEL  
NALA","date":"2013-03-20T02:50:57.927Z","site":"A"}  
} ]  
}

but when I try the same thing with a term query, I don't get any results.  
curl -XGET  
'[http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_search?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_search?pretty=true)'  
-d '{query:{"term": {"field1":"PITU"}}}'  
{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}

The strangest part is that when I change to search value to all lowercase,  
I get a valid result back  
curl -XGET  
'[http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_search?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_search?pretty=true)'  
-d '{query:{"term": {"field1":"pitu"}}}'  
{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 10.21034,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "test",  
"\_id" : "78116",  
"\_score" : 10.21034, "\_source" : {"id":78115,"field1":"_PITU_","field2":"DKBV  
GOAT","field3":"JXIX FPOZ WZIV","field4":"GQWZ AFHU VMJF  
AENE","field5":"BFEJ BEEX CHNM VCEL  
NALA","date":"2013-03-20T02:50:57.927Z","site":"A"}  
} ]  
}

Is this the expected behavior?

Also, I am still not sure what the difference between term/match/field  
query is. Any help (or links to related questions) would be appreciated.

Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [March 20, 2013, 9:58pm UTC](https://discuss.elastic.co/t/term-query-question/11229/2 "2013-03-20T21:58:49Z")

</div>

Term queries are not analyzed. The term being searched for must match  
exactly the term that was indexed. Without knowing your mapping, I  
am assuming that field1 is analyzed by the standard analyzer, which means  
the tokens are lowercased before being indexed.

Analysis is a Lucene-level concept (actually text analysis in general), so  
you can better understand analyzed/non-analyzed concepts by reading about  
Lucene:  
[http://lucene.apache.org/core/4\_2\_0/core/org/apache/lucene/analysis/package-summary.html](http://lucene.apache.org/core/4_2_0/core/org/apache/lucene/analysis/package-summary.html)

NOTE: I know that Elasticsearch documentation is being worked on, but this  
core concept needs to be addressed up front.

--  
Ivan

On Wed, Mar 20, 2013 at 2:49 PM, Fish Tastic [whoisbingo@gmail.com](mailto:whoisbingo@gmail.com) wrote:

> I created some random data to test search.
> 
> When it do I match query, it works fine.  
> curl -XGET '  
> [http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_search?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_search?pretty=true)'  
> -d '{query:{"match": {"field1":"PITU"}}}'  
> {  
> "took" : 3,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 10.21034,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "test",  
> "\_id" : "78116",  
> "\_score" : 10.21034, "\_source" : {"id":78115,"field1":"_PITU_","field2":"DKBV  
> GOAT","field3":"JXIX FPOZ WZIV","field4":"GQWZ AFHU VMJF  
> AENE","field5":"BFEJ BEEX CHNM VCEL  
> NALA","date":"2013-03-20T02:50:57.927Z","site":"A"}  
> } ]  
> }
> 
> but when I try the same thing with a term query, I don't get any results.  
> curl -XGET '  
> [http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_search?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_search?pretty=true)'  
> -d '{query:{"term": {"field1":"PITU"}}}'  
> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }
> 
> The strangest part is that when I change to search value to all lowercase,  
> I get a valid result back  
> curl -XGET '  
> [http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_search?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_search?pretty=true)'  
> -d '{query:{"term": {"field1":"pitu"}}}'  
> {  
> "took" : 2,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 10.21034,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "test",  
> "\_id" : "78116",  
> "\_score" : 10.21034, "\_source" : {"id":78115,"field1":"_PITU_","field2":"DKBV  
> GOAT","field3":"JXIX FPOZ WZIV","field4":"GQWZ AFHU VMJF  
> AENE","field5":"BFEJ BEEX CHNM VCEL  
> NALA","date":"2013-03-20T02:50:57.927Z","site":"A"}  
> } ]  
> }
> 
> Is this the expected behavior?
> 
> Also, I am still not sure what the difference between term/match/field  
> query is. Any help (or links to related questions) would be appreciated.
> 
> Thanks!
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Fish\_Tastic](https://avatars.discourse-cdn.com/v4/letter/f/4bbf92/32.png) [@Fish\_Tastic](https://discuss.elastic.co/u/Fish_Tastic)\
**Post date:** [March 20, 2013, 10:08pm UTC](https://discuss.elastic.co/t/term-query-question/11229/3 "2013-03-20T22:08:01Z")

</div>

Thanks, that's kinda what I was thinking as well. I didn't use any special  
analyzer so everything probably just turned lowercased. The documentation  
mentioned about not\_analyzed but it wasn't detailed enough.

Here is my mapping:

curl -XGET  
'[http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_mapping?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_mapping?pretty=true)'  
{  
"test" : {  
"properties" : {  
"date" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"field1" : {  
"type" : "string"  
},  
"field2" : {  
"type" : "string"  
},  
"field3" : {  
"type" : "string"  
},  
"field4" : {  
"type" : "string"  
},  
"field5" : {  
"type" : "string"  
},  
"id" : {  
"type" : "long"  
},  
"site" : {  
"type" : "string"  
}  
}  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [March 20, 2013, 10:54pm UTC](https://discuss.elastic.co/t/term-query-question/11229/4 "2013-03-20T22:54:40Z")

</div>

If you want an exact match, then set the field as non\_analyzed and use a  
term query. In other words, only use a term query on non\_analyzed fields  
(the default for numerical fields).

It is up to your use case if a field should do an exact match. If you  
require both, look into multi fields:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--  
Ivan

On Wed, Mar 20, 2013 at 3:08 PM, Fish Tastic [whoisbingo@gmail.com](mailto:whoisbingo@gmail.com) wrote:

> Thanks, that's kinda what I was thinking as well. I didn't use any special  
> analyzer so everything probably just turned lowercased. The documentation  
> mentioned about not\_analyzed but it wasn't detailed enough.
> 
> Here is my mapping:
> 
> curl -XGET '  
> [http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_mapping?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_mapping?pretty=true)  
> '  
> {  
> "test" : {  
> "properties" : {  
> "date" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> },  
> "field1" : {  
> "type" : "string"  
> },  
> "field2" : {  
> "type" : "string"  
> },  
> "field3" : {  
> "type" : "string"  
> },  
> "field4" : {  
> "type" : "string"  
> },  
> "field5" : {  
> "type" : "string"  
> },  
> "id" : {  
> "type" : "long"  
> },  
> "site" : {  
> "type" : "string"  
> }  
> }  
> }  
> }
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![AHoS](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@AHoS](https://discuss.elastic.co/u/AHoS)\
**Post date:** [March 21, 2013, 1:21am UTC](https://discuss.elastic.co/t/term-query-question/11229/5 "2013-03-21T01:21:27Z")

</div>

as far as i know,if you didn't explicitly set the index parameter of a specific filed to "no" or "non\_analyzed",by default, it's analyzed.

I created some random data to test search.

When it do I match query, it works fine.  
curl -XGET  
'[http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_search?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_search?pretty=true)'  
-d '{query:{"match": {"field1":"PITU"}}}'  
{  
"took" : 3,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 10.21034,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "test",  
"\_id" : "78116",  
"\_score" : 10.21034, "\_source" : {"id":78115,"field1":"_PITU_","field2":"DKBV  
GOAT","field3":"JXIX FPOZ WZIV","field4":"GQWZ AFHU VMJF  
AENE","field5":"BFEJ BEEX CHNM VCEL  
NALA","date":"2013-03-20T02:50:57.927Z","site":"A"}  
} ]  
}

but when I try the same thing with a term query, I don't get any results.  
curl -XGET  
'[http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_search?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_search?pretty=true)'  
-d '{query:{"term": {"field1":"PITU"}}}'  
{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}

The strangest part is that when I change to search value to all lowercase,  
I get a valid result back  
curl -XGET  
'[http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/\_search?pretty=true](http://ec2-54-224-40-21.compute-1.amazonaws.com:9200/test/test/_search?pretty=true)'  
-d '{query:{"term": {"field1":"pitu"}}}'  
{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 10.21034,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "test",  
"\_id" : "78116",  
"\_score" : 10.21034, "\_source" : {"id":78115,"field1":"_PITU_","field2":"DKBV  
GOAT","field3":"JXIX FPOZ WZIV","field4":"GQWZ AFHU VMJF  
AENE","field5":"BFEJ BEEX CHNM VCEL  
NALA","date":"2013-03-20T02:50:57.927Z","site":"A"}  
} ]  
}

Is this the expected behavior?

Also, I am still not sure what the difference between term/match/field  
query is. Any help (or links to related questions) would be appreciated.

Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@.  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:45am UTC](https://discuss.elastic.co/t/term-query-question/11229/6 "2017-07-06T02:45:31Z")

</div>


