# Mapping question

**URL:** <https://discuss.elastic.co/t/mapping-question/16629>\
**Category:** Elasticsearch\
**Created:** [March 26, 2014, 10:03pm UTC](https://discuss.elastic.co/t/mapping-question/16629 "2014-03-26T22:03:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Parag\_Shah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parag_shah/32/44836_2.png) [@Parag\_Shah](https://discuss.elastic.co/u/Parag_Shah)\
**Post date:** [March 26, 2014, 10:03pm UTC](https://discuss.elastic.co/t/mapping-question/16629/1 "2014-03-26T22:03:55Z")

</div>

Hi all,

{  
"fruits" : {  
"apple" : {  
"sweet" : true,  
"color" : "red",  
"seed" : "red",  
"flesh" : "white"  
},  
"orange" : {  
"sweet" : true,  
"color" : "orange",  
"seed" : "white",  
"flesh" : "orange"  
}  
}  
}

The above is what I want to generate mappings for.

fruits is the container for different kinds of fruits.

I could add any other fruit (unknown) to "fruits" (known) like:

"banana" : {  
"sweet" : true,  
"color" : "yellow",  
"seed" : "black",  
"flesh" : "white"  
}

banana is a user-generated value, and for any fruit here and it has some  
attributes like sweet, color, seed and flesh.

I am not sure how I would do the mapping for this kind of a structure. Any  
help will be appreciated.

Regards  
Parag

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/589f48cc-c77a-4e71-9087-6c40d05a9588%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/589f48cc-c77a-4e71-9087-6c40d05a9588%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Kevin\_Wang](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@Kevin\_Wang](https://discuss.elastic.co/u/Kevin_Wang)\
**Post date:** [March 26, 2014, 10:13pm UTC](https://discuss.elastic.co/t/mapping-question/16629/2 "2014-03-26T22:13:03Z")

</div>

I think you can use Dynamic template for  
that [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-root-object-type.html#_dynamic_templates)

Regards,  
Kevin

On Thursday, March 27, 2014 9:03:55 AM UTC+11, Parag Shah wrote:

> Hi all,
> 
> {  
> "fruits" : {  
> "apple" : {  
> "sweet" : true,  
> "color" : "red",  
> "seed" : "red",  
> "flesh" : "white"  
> },  
> "orange" : {  
> "sweet" : true,  
> "color" : "orange",  
> "seed" : "white",  
> "flesh" : "orange"  
> }  
> }  
> }
> 
> The above is what I want to generate mappings for.
> 
> fruits is the container for different kinds of fruits.
> 
> I could add any other fruit (unknown) to "fruits" (known) like:
> 
> "banana" : {  
> "sweet" : true,  
> "color" : "yellow",  
> "seed" : "black",  
> "flesh" : "white"  
> }
> 
> banana is a user-generated value, and for any fruit here and it has some  
> attributes like sweet, color, seed and flesh.
> 
> I am not sure how I would do the mapping for this kind of a structure. Any  
> help will be appreciated.
> 
> Regards  
> Parag

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b1250ddd-cb40-440b-b0a0-fff909041486%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b1250ddd-cb40-440b-b0a0-fff909041486%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Parag\_Shah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parag_shah/32/44836_2.png) [@Parag\_Shah](https://discuss.elastic.co/u/Parag_Shah)\
**Post date:** [March 27, 2014, 5:14pm UTC](https://discuss.elastic.co/t/mapping-question/16629/3 "2014-03-27T17:14:27Z")

</div>

Hi Kevin,

```
I tried this. Does not seem to work for me. Do you have a working 

```

example? Also, remember, fruits is essentially a map. I also need to be  
able to search the keys in this map.

Regards  
Parag

On Wednesday, March 26, 2014 3:13:03 PM UTC-7, Kevin Wang wrote:

> I think you can use Dynamic template for that  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-root-object-type.html#_dynamic_templates)
> 
> Regards,  
> Kevin
> 
> On Thursday, March 27, 2014 9:03:55 AM UTC+11, Parag Shah wrote:
> 
> > Hi all,
> > 
> > {  
> > "fruits" : {  
> > "apple" : {  
> > "sweet" : true,  
> > "color" : "red",  
> > "seed" : "red",  
> > "flesh" : "white"  
> > },  
> > "orange" : {  
> > "sweet" : true,  
> > "color" : "orange",  
> > "seed" : "white",  
> > "flesh" : "orange"  
> > }  
> > }  
> > }
> > 
> > The above is what I want to generate mappings for.
> > 
> > fruits is the container for different kinds of fruits.
> > 
> > I could add any other fruit (unknown) to "fruits" (known) like:
> > 
> > "banana" : {  
> > "sweet" : true,  
> > "color" : "yellow",  
> > "seed" : "black",  
> > "flesh" : "white"  
> > }
> > 
> > banana is a user-generated value, and for any fruit here and it has some  
> > attributes like sweet, color, seed and flesh.
> > 
> > I am not sure how I would do the mapping for this kind of a structure.  
> > Any help will be appreciated.
> > 
> > Regards  
> > Parag

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/55357ca1-4226-4fdd-a759-7d09a0e2a6fb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/55357ca1-4226-4fdd-a759-7d09a0e2a6fb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Parag\_Shah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parag_shah/32/44836_2.png) [@Parag\_Shah](https://discuss.elastic.co/u/Parag_Shah)\
**Post date:** [March 27, 2014, 5:16pm UTC](https://discuss.elastic.co/t/mapping-question/16629/4 "2014-03-27T17:16:43Z")

</div>

Here is my schema:

{  
"settings": {  
"index": {  
"analysis": {  
"analyzer": {  
"starts\_with": {  
"tokenizer": "keyword",  
"filter": "lowercase"  
},  
"str\_search\_analyzer": {  
"tokenizer": "keyword",  
"filter": "lowercase"  
},  
"str\_index\_analyzer": {  
"tokenizer": "keyword",  
"filter": ["lowercase", "substring"]  
},  
"reverse": {  
"tokenizer": "keyword",  
"filter": "reverse"  
}  
},  
"filter": {  
"substring": {  
"type": "nGram",  
"min\_gram": 1,  
"max\_gram": 20  
}  
}  
}  
}  
},  
"mappings": {  
"fruits": {  
"dynamic\_templates" : [  
{  
"template\_1" : {  
"match" : "\*",  
"match\_mapping\_type" : "string",  
"mapping": {  
"type": "object",  
"index": "not\_analyzed",  
"properties": {  
"flesh": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"sweet": {  
"type": "boolean"  
},  
"seed": {  
"type": "string",  
"index" : "not\_analyzed"  
},  
"skin": {  
"type": "string",  
"index" : "not\_analyzed"  
}  
}  
}  
}  
},  
{  
"template\_2": {

```
                    "match": "multi*",
                    "fields": {
                        "{name}": {
                            "type": "string",
                            "index": "analyzed"
                        },
                        "starts_with_{name}": {
                            "type": "string",
                            "index": "not_analyzed",
                            "analyzer": "starts_with"
                        },
                        "equals_{name}": {
                            "type": "string",
                            "index": "not_analyzed"
                        },
                        "contains_{name}": {
                            "type": "string",
                            "search_analyzer": "str_search_analyzer",
                            "index_analyzer": "str_index_analyzer"
                        },
                        "ends_with_{name}": {
                            "type": "string",
                            "analyzer": "reverse"
                        }
                    }
                }
            }

        ]
    }
}

```

}

On Thu, Mar 27, 2014 at 10:14 AM, Parag Shah [parags@gmail.com](mailto:parags@gmail.com) wrote:

> Hi Kevin,
> 
> ```
> I tried this. Does not seem to work for me. Do you have a working
> 
> ```
> 
> example? Also, remember, fruits is essentially a map. I also need to be  
> able to search the keys in this map.
> 
> Regards  
> Parag
> 
> On Wednesday, March 26, 2014 3:13:03 PM UTC-7, Kevin Wang wrote:
> 
> > I think you can use Dynamic template for that [http://www.elasticsearch](http://www.elasticsearch).  
> > org/guide/en/elasticsearch/reference/current/mapping-  
> > root-object-type.html#\_dynamic\_templates
> > 
> > Regards,  
> > Kevin
> > 
> > On Thursday, March 27, 2014 9:03:55 AM UTC+11, Parag Shah wrote:
> > 
> > > Hi all,
> > > 
> > > {  
> > > "fruits" : {  
> > > "apple" : {  
> > > "sweet" : true,  
> > > "color" : "red",  
> > > "seed" : "red",  
> > > "flesh" : "white"  
> > > },  
> > > "orange" : {  
> > > "sweet" : true,  
> > > "color" : "orange",  
> > > "seed" : "white",  
> > > "flesh" : "orange"  
> > > }  
> > > }  
> > > }
> > > 
> > > The above is what I want to generate mappings for.
> > > 
> > > fruits is the container for different kinds of fruits.
> > > 
> > > I could add any other fruit (unknown) to "fruits" (known) like:
> > > 
> > > "banana" : {  
> > > "sweet" : true,  
> > > "color" : "yellow",  
> > > "seed" : "black",  
> > > "flesh" : "white"  
> > > }
> > > 
> > > banana is a user-generated value, and for any fruit here and it has some  
> > > attributes like sweet, color, seed and flesh.
> > > 
> > > I am not sure how I would do the mapping for this kind of a structure.  
> > > Any help will be appreciated.
> > > 
> > > Regards  
> > > Parag
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/aplw3dpwe00/unsubscribe](https://groups.google.com/d/topic/elasticsearch/aplw3dpwe00/unsubscribe).  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/55357ca1-4226-4fdd-a759-7d09a0e2a6fb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/55357ca1-4226-4fdd-a759-7d09a0e2a6fb%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/55357ca1-4226-4fdd-a759-7d09a0e2a6fb%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/55357ca1-4226-4fdd-a759-7d09a0e2a6fb%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAD2b%2BQ3v36ZLFwcmh0LfiCwc-hF9ZOobdtASq7TtPT5-xg21ZQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAD2b%2BQ3v36ZLFwcmh0LfiCwc-hF9ZOobdtASq7TtPT5-xg21ZQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:40am UTC](https://discuss.elastic.co/t/mapping-question/16629/5 "2017-07-06T01:40:05Z")

</div>


