# Question About Dynamic Mappings and Multi-Field-Type

**URL:** <https://discuss.elastic.co/t/question-about-dynamic-mappings-and-multi-field-type/5830>\
**Category:** Elasticsearch\
**Created:** [November 9, 2011, 8:53pm UTC](https://discuss.elastic.co/t/question-about-dynamic-mappings-and-multi-field-type/5830 "2011-11-09T20:53:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LORDs\_diakonos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lords_diakonos/32/3009_2.png) [@LORDs\_diakonos](https://discuss.elastic.co/u/LORDs_diakonos)\
**Post date:** [November 9, 2011, 8:53pm UTC](https://discuss.elastic.co/t/question-about-dynamic-mappings-and-multi-field-type/5830/1 "2011-11-09T20:53:37Z")

</div>

I am having issues sorting because I am using the WhiteSpace Analyzer  
and my field data is "Some Title" I get why it does work

\<custom:"product.title":  
org.elasticsearch.index.field.data.strings.StringFieldDataType  
$1@164146a7\>]: Query Failed [Failed to execute main query]]; nested:  
IOException[Can't sort on string types with more than one value per  
doc, or more than one token per field]; }

My question is this. I don't use static mappings but want to use  
Multi-Field-Type [http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)

So

1. Can I set all fields to be Multi-Field-Type?
2. Can I when construction the JSON to index somehow let ElasticSearch  
now to make this field be Multi-Field-Type?

We have ElasticSearch embedded and use the JavaAPI to interact

---

<div class="post-metadata">

**Author:** ![Gabriel\_Farrell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_farrell/32/3337_2.png) [@Gabriel\_Farrell](https://discuss.elastic.co/u/Gabriel_Farrell)\
**Post date:** [November 10, 2011, 5:21pm UTC](https://discuss.elastic.co/t/question-about-dynamic-mappings-and-multi-field-type/5830/2 "2011-11-10T17:21:50Z")

</div>

Have you looked at dynamic mapping?

> **[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.

On Wed, Nov 9, 2011 at 3:53 PM, LORDs\_diakonos [jasontesser@gmail.com](mailto:jasontesser@gmail.com) wrote:

> I am having issues sorting because I am using the WhiteSpace Analyzer  
> and my field data is "Some Title" I get why it does work
> 
> \<custom:"product.title":  
> org.elasticsearch.index.field.data.strings.StringFieldDataType  
> $1@164146a7\>]: Query Failed [Failed to execute main query]]; nested:  
> IOException[Can't sort on string types with more than one value per  
> doc, or more than one token per field]; }
> 
> My question is this. I don't use static mappings but want to use  
> Multi-Field-Type [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)
> 
> So
> 
> 1. Can I set all fields to be Multi-Field-Type?
> 2. Can I when construction the JSON to index somehow let Elasticsearch  
> now to make this field be Multi-Field-Type?
> 
> We have Elasticsearch embedded and use the JavaAPI to interact

---

<div class="post-metadata">

**Author:** ![Gabriel\_Farrell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_farrell/32/3337_2.png) [@Gabriel\_Farrell](https://discuss.elastic.co/u/Gabriel_Farrell)\
**Post date:** [November 10, 2011, 5:31pm UTC](https://discuss.elastic.co/t/question-about-dynamic-mappings-and-multi-field-type/5830/3 "2011-11-10T17:31:17Z")

</div>

Sorry sent that before I finished. With a dynamic mapping you should  
be able to do something like the following:

{  
"mappings": {  
"_default_": {  
"dynamic\_templates": [  
{  
"base": {  
"match": "\*\_sort",  
"mapping": {  
"type": "multi\_field",  
"fields": {  
"{name}": {"type": "string"},  
"sort": {"type": "string", "analyzer": "sort"}  
}  
}  
}  
}  
]  
}  
},  
"settings": {  
"analysis": {  
"analyzer": {  
"sort": {  
"type": "custom",  
"tokenizer": "keyword",  
"filter": "lowercase"  
}  
}  
}  
}  
}

This was the create-index JSON I used to take any field ending in  
"\_sort" and add a ".sort" multifield for sorting, using a custom  
"sort" analyzer. I hope that helps for the Java API -- I've only used  
HTTP.

On Thu, Nov 10, 2011 at 12:21 PM, Gabriel Farrell [gsf747@gmail.com](mailto:gsf747@gmail.com) wrote:

> Have you looked at dynamic mapping?  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/dynamic-mapping.html)
> 
> On Wed, Nov 9, 2011 at 3:53 PM, LORDs\_diakonos [jasontesser@gmail.com](mailto:jasontesser@gmail.com) wrote:
> 
> > I am having issues sorting because I am using the WhiteSpace Analyzer  
> > and my field data is "Some Title" I get why it does work
> > 
> > \<custom:"product.title":  
> > org.elasticsearch.index.field.data.strings.StringFieldDataType  
> > $1@164146a7\>]: Query Failed [Failed to execute main query]]; nested:  
> > IOException[Can't sort on string types with more than one value per  
> > doc, or more than one token per field]; }
> > 
> > My question is this. I don't use static mappings but want to use  
> > Multi-Field-Type [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)
> > 
> > So
> > 
> > 1. Can I set all fields to be Multi-Field-Type?
> > 2. Can I when construction the JSON to index somehow let Elasticsearch  
> > now to make this field be Multi-Field-Type?
> > 
> > We have Elasticsearch embedded and use the JavaAPI to interact

---

<div class="post-metadata">

**Author:** ![LORDs\_diakonos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lords_diakonos/32/3009_2.png) [@LORDs\_diakonos](https://discuss.elastic.co/u/LORDs_diakonos)\
**Post date:** [November 10, 2011, 6:28pm UTC](https://discuss.elastic.co/t/question-about-dynamic-mappings-and-multi-field-type/5830/4 "2011-11-10T18:28:15Z")

</div>

Well I used this mapping BUT the problem is I get double results when  
Searching now. I added a .org to when I sort.

Any Ideas on the double Mapping

{

```
 "content": {

 "dynamic_templates": [

      {

          "template_1": {

                "match": "*",

                "mapping": {

                     "type": "multi_field",

                     "fields": {

                          "{name}": {

                               "type": "{dynamic_type}","index":

```

"analyzed","store": "yes"

```
                           },

                          "org": {

                               "type": "{dynamic_type}","index":

```

"not\_analyzed","store": "yes"

```
                          }

                     }

                }

          }

     }

]

```

}

}

Thanks,  
Jason Tesser  
dotCMS Director, Support Services  
1-305-858-1422

On Thu, Nov 10, 2011 at 12:31 PM, Gabriel Farrell [gsf747@gmail.com](mailto:gsf747@gmail.com) wrote:

> Sorry sent that before I finished. With a dynamic mapping you should  
> be able to do something like the following:
> 
> {  
> "mappings": {  
> "_default_": {  
> "dynamic\_templates": [  
> {  
> "base": {  
> "match": "\*\_sort",  
> "mapping": {  
> "type": "multi\_field",  
> "fields": {  
> "{name}": {"type": "string"},  
> "sort": {"type": "string", "analyzer": "sort"}  
> }  
> }  
> }  
> }  
> ]  
> }  
> },  
> "settings": {  
> "analysis": {  
> "analyzer": {  
> "sort": {  
> "type": "custom",  
> "tokenizer": "keyword",  
> "filter": "lowercase"  
> }  
> }  
> }  
> }  
> }
> 
> This was the create-index JSON I used to take any field ending in  
> "\_sort" and add a ".sort" multifield for sorting, using a custom  
> "sort" analyzer. I hope that helps for the Java API -- I've only used  
> HTTP.
> 
> On Thu, Nov 10, 2011 at 12:21 PM, Gabriel Farrell [gsf747@gmail.com](mailto:gsf747@gmail.com)  
> wrote:
> 
> > Have you looked at dynamic mapping?
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/dynamic-mapping.html)
> 
> > On Wed, Nov 9, 2011 at 3:53 PM, LORDs\_diakonos [jasontesser@gmail.com](mailto:jasontesser@gmail.com)  
> > wrote:
> > 
> > > I am having issues sorting because I am using the WhiteSpace Analyzer  
> > > and my field data is "Some Title" I get why it does work
> > > 
> > > \<custom:"product.title":  
> > > org.elasticsearch.index.field.data.strings.StringFieldDataType  
> > > $1@164146a7\>]: Query Failed [Failed to execute main query]]; nested:  
> > > IOException[Can't sort on string types with more than one value per  
> > > doc, or more than one token per field]; }
> > > 
> > > My question is this. I don't use static mappings but want to use  
> > > Multi-Field-Type  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)
> > > 
> > > So
> > > 
> > > 1. Can I set all fields to be Multi-Field-Type?
> > > 2. Can I when construction the JSON to index somehow let Elasticsearch  
> > > now to make this field be Multi-Field-Type?
> > > 
> > > We have Elasticsearch embedded and use the JavaAPI to interact

---

<div class="post-metadata">

**Author:** ![LORDs\_diakonos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lords_diakonos/32/3009_2.png) [@LORDs\_diakonos](https://discuss.elastic.co/u/LORDs_diakonos)\
**Post date:** [November 10, 2011, 6:29pm UTC](https://discuss.elastic.co/t/question-about-dynamic-mappings-and-multi-field-type/5830/5 "2011-11-10T18:29:12Z")

</div>

I mean Double Search Results. Any ideas?

Thanks,  
Jason Tesser  
dotCMS Director, Support Services  
1-305-858-1422

On Thu, Nov 10, 2011 at 1:28 PM, Jason Tesser [jasontesser@gmail.com](mailto:jasontesser@gmail.com) wrote:

> Well I used this mapping BUT the problem is I get double results when  
> Searching now. I added a .org to when I sort.
> 
> Any Ideas on the double Mapping
> 
> {
> 
> ```
> "content": {
> 
> "dynamic_templates": [
> 
> {
> 
> "template_1": {
> 
> "match": "*",
> 
> "mapping": {
> 
> "type": "multi_field",
> 
> "fields": {
> 
> "{name}": {
> 
> "type": "{dynamic_type}","index":
> 
> ```
> 
> "analyzed","store": "yes"
> 
> ```
> },
> 
> "org": {
> 
> "type": "{dynamic_type}","index":
> 
> ```
> 
> "not\_analyzed","store": "yes"
> 
> ```
> }
> 
> }
> 
> }
> 
> }
> 
> }
> 
> ]
> 
> ```
> 
> }
> 
> }
> 
> Thanks,  
> Jason Tesser  
> dotCMS Director, Support Services  
> 1-305-858-1422
> 
> On Thu, Nov 10, 2011 at 12:31 PM, Gabriel Farrell [gsf747@gmail.com](mailto:gsf747@gmail.com)wrote:
> 
> > Sorry sent that before I finished. With a dynamic mapping you should  
> > be able to do something like the following:
> > 
> > {  
> > "mappings": {  
> > "_default_": {  
> > "dynamic\_templates": [  
> > {  
> > "base": {  
> > "match": "\*\_sort",  
> > "mapping": {  
> > "type": "multi\_field",  
> > "fields": {  
> > "{name}": {"type": "string"},  
> > "sort": {"type": "string", "analyzer": "sort"}  
> > }  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > },  
> > "settings": {  
> > "analysis": {  
> > "analyzer": {  
> > "sort": {  
> > "type": "custom",  
> > "tokenizer": "keyword",  
> > "filter": "lowercase"  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > This was the create-index JSON I used to take any field ending in  
> > "\_sort" and add a ".sort" multifield for sorting, using a custom  
> > "sort" analyzer. I hope that helps for the Java API -- I've only used  
> > HTTP.
> > 
> > On Thu, Nov 10, 2011 at 12:21 PM, Gabriel Farrell [gsf747@gmail.com](mailto:gsf747@gmail.com)  
> > wrote:
> > 
> > > Have you looked at dynamic mapping?
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/dynamic-mapping.html)
> > 
> > > On Wed, Nov 9, 2011 at 3:53 PM, LORDs\_diakonos [jasontesser@gmail.com](mailto:jasontesser@gmail.com)  
> > > wrote:
> > > 
> > > > I am having issues sorting because I am using the WhiteSpace Analyzer  
> > > > and my field data is "Some Title" I get why it does work
> > > > 
> > > > \<custom:"product.title":  
> > > > org.elasticsearch.index.field.data.strings.StringFieldDataType  
> > > > $1@164146a7\>]: Query Failed [Failed to execute main query]]; nested:  
> > > > IOException[Can't sort on string types with more than one value per  
> > > > doc, or more than one token per field]; }
> > > > 
> > > > My question is this. I don't use static mappings but want to use  
> > > > Multi-Field-Type  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)
> > > > 
> > > > So
> > > > 
> > > > 1. Can I set all fields to be Multi-Field-Type?
> > > > 2. Can I when construction the JSON to index somehow let Elasticsearch  
> > > > now to make this field be Multi-Field-Type?
> > > > 
> > > > We have Elasticsearch embedded and use the JavaAPI to interact

---

<div class="post-metadata">

**Author:** ![LORDs\_diakonos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lords_diakonos/32/3009_2.png) [@LORDs\_diakonos](https://discuss.elastic.co/u/LORDs_diakonos)\
**Post date:** [November 10, 2011, 8:26pm UTC](https://discuss.elastic.co/t/question-about-dynamic-mappings-and-multi-field-type/5830/6 "2011-11-10T20:26:01Z")

</div>

OK this all works. Sorry I was confussed about my own content :-p  
Not duplicated. Dynamic mappings working.

From Java I called this way for those interested

indicesAdminClient.prepareCreate(indexName)  
.addMapping("content", new String(FileUtil.getBytes(new  
File(url.getPath()))))  
.setSettings(

On Nov 10, 1:29 pm, Jason Tesser [jasontes...@gmail.com](mailto:jasontes...@gmail.com) wrote:

> I mean Double Search Results. Any ideas?
> 
> Thanks,  
> Jason Tesser  
> dotCMS Director, Support Services  
> 1-305-858-1422
> 
> On Thu, Nov 10, 2011 at 1:28 PM, Jason Tesser [jasontes...@gmail.com](mailto:jasontes...@gmail.com) wrote:
> 
> > Well I used this mapping BUT the problem is I get double results when  
> > Searching now. I added a .org to when I sort.
> 
> > Any Ideas on the double Mapping
> 
> > {
> 
> > ```
> > "content": {
> > 
> > ```
> 
> > ```
> > "dynamic_templates": [
> > 
> > ```
> 
> > ```
> > {
> > 
> > ```
> 
> > ```
> > "template_1": {
> > 
> > ```
> 
> > ```
> > "match": "*",
> > 
> > ```
> 
> > ```
> > "mapping": {
> > 
> > ```
> 
> > ```
> > "type": "multi_field",
> > 
> > ```
> 
> > ```
> > "fields": {
> > 
> > ```
> 
> > ```
> > "{name}": {
> > 
> > ```
> 
> > ```
> > "type": "{dynamic_type}","index":
> > 
> > ```
> > 
> > "analyzed","store": "yes"
> 
> > ```
> > },
> > 
> > ```
> 
> > ```
> > "org": {
> > 
> > ```
> 
> > ```
> > "type": "{dynamic_type}","index":
> > 
> > ```
> > 
> > "not\_analyzed","store": "yes"
> 
> > ```
> > }
> > 
> > ```
> 
> > ```
> > }
> > 
> > ```
> 
> > ```
> > }
> > 
> > ```
> 
> > ```
> > }
> > 
> > ```
> 
> > ```
> > }
> > 
> > ```
> 
> > ```
> > ]
> > 
> > ```
> 
> > }
> 
> > }
> 
> > Thanks,  
> > Jason Tesser  
> > dotCMS Director, Support Services  
> > 1-305-858-1422
> 
> > On Thu, Nov 10, 2011 at 12:31 PM, Gabriel Farrell [gsf...@gmail.com](mailto:gsf...@gmail.com)wrote:
> 
> > > Sorry sent that before I finished. With a dynamic mapping you should  
> > > be able to do something like the following:
> 
> > > {  
> > > "mappings": {  
> > > "_default_": {  
> > > "dynamic\_templates": [  
> > > {  
> > > "base": {  
> > > "match": "\*\_sort",  
> > > "mapping": {  
> > > "type": "multi\_field",  
> > > "fields": {  
> > > "{name}": {"type": "string"},  
> > > "sort": {"type": "string", "analyzer": "sort"}  
> > > }  
> > > }  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > },  
> > > "settings": {  
> > > "analysis": {  
> > > "analyzer": {  
> > > "sort": {  
> > > "type": "custom",  
> > > "tokenizer": "keyword",  
> > > "filter": "lowercase"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> 
> > > This was the create-index JSON I used to take any field ending in  
> > > "\_sort" and add a ".sort" multifield for sorting, using a custom  
> > > "sort" analyzer. I hope that helps for the Java API -- I've only used  
> > > HTTP.
> 
> > > On Thu, Nov 10, 2011 at 12:21 PM, Gabriel Farrell [gsf...@gmail.com](mailto:gsf...@gmail.com)  
> > > wrote:
> > > 
> > > > Have you looked at dynamic mapping?
> 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/dynamic-mapping)....
> 
> > > > On Wed, Nov 9, 2011 at 3:53 PM, LORDs\_diakonos [jasontes...@gmail.com](mailto:jasontes...@gmail.com)  
> > > > wrote:
> > > > 
> > > > > I am having issues sorting because I am using the WhiteSpace Analyzer  
> > > > > and my field data is "Some Title" I get why it does work
> 
> > > > > \<custom:"product.title":  
> > > > > org.elasticsearch.index.field.data.strings.StringFieldDataType  
> > > > > $1@164146a7\>]: Query Failed [Failed to execute main query]]; nested:  
> > > > > IOException[Can't sort on string types with more than one value per  
> > > > > doc, or more than one token per field]; }
> 
> > > > > My question is this. I don't use static mappings but want to use  
> > > > > Multi-Field-Type  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type)...
> 
> > > > > So
> > > > > 
> > > > > 1. Can I set all fields to be Multi-Field-Type?
> > > > > 2. Can I when construction the JSON to index somehow let Elasticsearch  
> > > > > now to make this field be Multi-Field-Type?
> 
> > > > > We have Elasticsearch embedded and use the JavaAPI to interact

---

<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:49am UTC](https://discuss.elastic.co/t/question-about-dynamic-mappings-and-multi-field-type/5830/7 "2017-07-06T03:49:07Z")

</div>


