# Dynamic doc Mapping

**URL:** <https://discuss.elastic.co/t/dynamic-doc-mapping/12792>\
**Category:** Elasticsearch\
**Created:** [July 15, 2013, 6:37pm UTC](https://discuss.elastic.co/t/dynamic-doc-mapping/12792 "2013-07-15T18:37:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustavo\_Chain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavo_chain/32/2109_2.png) [@Gustavo\_Chain](https://discuss.elastic.co/u/Gustavo_Chain)\
**Post date:** [July 15, 2013, 6:37pm UTC](https://discuss.elastic.co/t/dynamic-doc-mapping/12792/1 "2013-07-15T18:37:27Z")

</div>

Hi, I'm trying to index results of a questionnaire App.

Users can create questionnaires with one or more questions where answers  
can have a numeric or text response.  
So, a sample document will look like:

result: {  
questionnaire\_id: 1,  
responses: [  
{question\_id: 1, value: 1},  
{question\_id: 2, value: 'some text'}  
]  
}

So as each questionnaire is different, should I create a different type for  
each different questionnaire? or using a nested type (for responses field)  
would be a better approach?  
The idea would be to query for ranges on numeric values and make a full  
text search on text values.

Thanks in advice!

--  
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:** ![Benjamin\_Sanders](https://avatars.discourse-cdn.com/v4/letter/b/0ea827/32.png) [@Benjamin\_Sanders](https://discuss.elastic.co/u/Benjamin_Sanders)\
**Post date:** [July 15, 2013, 7:55pm UTC](https://discuss.elastic.co/t/dynamic-doc-mapping/12792/2 "2013-07-15T19:55:23Z")

</div>

Hello Gustavo,

I am no expert, but I have a couple thoughts that might get you thinking  
down the right path.

1. You could name the value fields according to their data type, allowing  
numeric data to be indexed and analyzed separately from text. ie:

result: {  
questionnaire\_id: 1,  
responses: [  
{question\_id: 1, value\_numeric: 1},  
{question\_id: 2, value\_text: 'some text'}  
]  
}

The dynamic mapping would see the response object as having one of a list  
of possible fields.

1. You could configure your mapper to treat it all as text. If you are not  
as concerned with data type, and don't plan on doing numerical analytics on  
the data in this index, then take advantage of the configurable nature of  
the dynamic mapping to treat everything in the value field as text. See:  
[http://www.elasticsearch.org/guide/reference/mapping/root-object-type/](http://www.elasticsearch.org/guide/reference/mapping/root-object-type/)

I hope that helps,

- Ben

--  
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:** ![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:26am UTC](https://discuss.elastic.co/t/dynamic-doc-mapping/12792/3 "2017-07-06T02:26:24Z")

</div>


