# Multi\_field mappings and terms query

**URL:** <https://discuss.elastic.co/t/multi-field-mappings-and-terms-query/8087>\
**Category:** Elasticsearch\
**Created:** [June 13, 2012, 7:59pm UTC](https://discuss.elastic.co/t/multi-field-mappings-and-terms-query/8087 "2012-06-13T19:59:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Yankus](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@Jason\_Yankus](https://discuss.elastic.co/u/Jason_Yankus)\
**Post date:** [June 13, 2012, 7:59pm UTC](https://discuss.elastic.co/t/multi-field-mappings-and-terms-query/8087/1 "2012-06-13T19:59:34Z")

</div>

Greetings,

I need to perform a terms query against a field that contains string data  
that may contain whitespace. This an example of my current mapping:

"docType" : {  
"type" : "multi\_field",  
"fields" : {  
"docType" : {  
"type" : "string"  
},  
"na" : {  
"type" : "string",  
"analyzer" : "keyword",  
"include\_in\_all" : false  
}  
}  
}

When I perform a terms query against that data, like this:

curl -XGET 'localhost:9200/test/\_search?pretty=true' -d '{  
"query" : {  
"terms" : { "docType.na" : ["compliance report", "other"] }  
}  
}'

I get the following:

{  
"took" : 33,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

If I don't attempt to use the '.na' field I only get results for "other"  
and not "compliance report." Does the in/terms query work against  
multi\_field mappings? If so, how do I use it?

Thanks,

-jason

---

<div class="post-metadata">

**Author:** ![Jason\_Yankus](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@Jason\_Yankus](https://discuss.elastic.co/u/Jason_Yankus)\
**Post date:** [June 13, 2012, 8:22pm UTC](https://discuss.elastic.co/t/multi-field-mappings-and-terms-query/8087/2 "2012-06-13T20:22:26Z")

</div>

Ok. I think I solved my own problem and will document it here.

I was automatically lowercasing the search values as they were added to the  
terms collection. This is pretty standard for analyzed ES fields but for  
the non-analyzed fields the matching is case sensitive.

So, when the data in the terms query changed from 'compliance report' to  
'Compliance Report' the results magically came back.

Problem solved.

-jason

On Wednesday, June 13, 2012 3:59:34 PM UTC-4, Jason Yankus wrote:

> Greetings,
> 
> I need to perform a terms query against a field that contains string data  
> that may contain whitespace. This an example of my current mapping:
> 
> "docType" : {  
> "type" : "multi\_field",  
> "fields" : {  
> "docType" : {  
> "type" : "string"  
> },  
> "na" : {  
> "type" : "string",  
> "analyzer" : "keyword",  
> "include\_in\_all" : false  
> }  
> }  
> }
> 
> When I perform a terms query against that data, like this:
> 
> curl -XGET 'localhost:9200/test/\_search?pretty=true' -d '{  
> "query" : {  
> "terms" : { "docType.na" : ["compliance report", "other"] }  
> }  
> }'
> 
> I get the following:
> 
> {  
> "took" : 33,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> If I don't attempt to use the '.na' field I only get results for "other"  
> and not "compliance report." Does the in/terms query work against  
> multi\_field mappings? If so, how do I use it?
> 
> Thanks,
> 
> -jason

---

<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, 3:24am UTC](https://discuss.elastic.co/t/multi-field-mappings-and-terms-query/8087/3 "2017-07-06T03:24:20Z")

</div>

Closed on July 6, 2017, 3:24am UTC


