# How to query write query for given mapping?

**URL:** <https://discuss.elastic.co/t/how-to-query-write-query-for-given-mapping/50598>\
**Category:** Elasticsearch\
**Created:** [May 20, 2016, 6:59pm UTC](https://discuss.elastic.co/t/how-to-query-write-query-for-given-mapping/50598 "2016-05-20T18:59:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tester](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@tester](https://discuss.elastic.co/u/tester)\
**Post date:** [May 20, 2016, 6:59pm UTC](https://discuss.elastic.co/t/how-to-query-write-query-for-given-mapping/50598/1 "2016-05-20T18:59:31Z")

</div>

Hi,

Thank you reading this newbie question. Elasticsearch instance has mapping (see below) and 10+MM documents. Question is how to query? e.g. consider name is "official\_mail\_id" and description is "tester@gmail.com"

Thank you in advance for any help.

Mapping:  
{  
"head" : {  
"mappings" : {  
"page" : {  
"properties" : {  
"templates" : {  
"properties" : {  
"description" : {  
"type" : "string"  
},  
"name" : {  
"type" : "string"  
}  
}  
}  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [May 20, 2016, 7:33pm UTC](https://discuss.elastic.co/t/how-to-query-write-query-for-given-mapping/50598/2 "2016-05-20T19:33:02Z")

</div>

If you don't expect to have too many different "names", it might be better to create individual fields instead of pilling them into a single field. In other words index

```auto
{
    "official_mail_id": "tester@gmail.com"
}

```

instead of

```auto
{
    "name": "official_mail_id",
    "description": "tester@gmail.com"
}

```

Otherwise, if you have multiple names and descriptions per document, the relationship between the descriptions and their names and is not preserved after indexing. Making search for a particular description in a particular field not possible.

This problem can be solved by switching to [nested objects](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/nested-objects.html), but at the expense of search performance and index size.

---

<div class="post-metadata">

**Author:** ![tester](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@tester](https://discuss.elastic.co/u/tester)\
**Post date:** [May 23, 2016, 8:39am UTC](https://discuss.elastic.co/t/how-to-query-write-query-for-given-mapping/50598/3 "2016-05-23T08:39:46Z")

</div>

Hi Igor,  
Thank you for response. there are multiple "name" and associated "description" with it. I had just copy pasted important to me. Apologies for the same.  
I am going ahead with planning new mapping which dev team should accommodate. I will keep results posted.  
Regards,

---

<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:49pm UTC](https://discuss.elastic.co/t/how-to-query-write-query-for-given-mapping/50598/4 "2017-07-05T22:49:51Z")

</div>


