# Default not analyzed?

**URL:** <https://discuss.elastic.co/t/default-not-analyzed/4299>\
**Category:** Elasticsearch\
**Created:** [April 26, 2011, 9:29pm UTC](https://discuss.elastic.co/t/default-not-analyzed/4299 "2011-04-26T21:29:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacorob](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jacorob](https://discuss.elastic.co/u/jacorob)\
**Post date:** [April 26, 2011, 9:29pm UTC](https://discuss.elastic.co/t/default-not-analyzed/4299/1 "2011-04-26T21:29:51Z")

</div>

I use dynamic mapping for my index since my fields will change per  
document. By default I don't want any of the fields analyzed. Can I do  
this while still using dynamic mappings?

Bob

---

<div class="post-metadata">

**Author:** ![jacorob](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jacorob](https://discuss.elastic.co/u/jacorob)\
**Post date:** [April 26, 2011, 10:41pm UTC](https://discuss.elastic.co/t/default-not-analyzed/4299/2 "2011-04-26T22:41:31Z")

</div>

So after more reading it appears templates are the way to go. Looking  
at

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

it appears that I want something like:

{  
"person" : {  
"dynamic\_templates" : [  
{  
"store\_generic" : {  
"match" : "\*",  
"mapping" : {  
"store" : "yes"  
}  
}  
}  
]  
}  
}

Unfortunately 'm having difficulty translating this example to the  
appropriate Java API calls. In particular, it doesn't seem to specify  
a "type" which PutIndexTemplateRequestBuilder.addMapping appears to  
require. It also doesn't have properties, etc. I've looked at  
simpleIndexTemplateTests in the elasticsearch integration tests which  
showed examples when specifying types, properties, etc. but not a  
simple case like above. I'm also confused by what "person" and  
"dynamic\_templates" represent in the above example.

I'm sure I'm just doing something wrong, but I haven't hit on the  
magic formula yet in my API calls. Any tips on how the above would be  
converted to the appropriate java API call would be most appreciated.

Thanks,  
Bob

On Apr 26, 4:29 pm, Bob [jaco...@gmail.com](mailto:jaco...@gmail.com) wrote:

> I use dynamic mapping for my index since my fields will change per  
> document. By default I don't want any of the fields analyzed. Can I do  
> this while still using dynamic mappings?
> 
> Bob

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 27, 2011, 5:13pm UTC](https://discuss.elastic.co/t/default-not-analyzed/4299/3 "2011-04-27T17:13:17Z")

</div>

person is the name of the type. What you would want to do is use dynamic template on string types, and specific the index to be not\_analyzed. When using the Java API, you just need to build the json that represents it.  
On Wednesday, April 27, 2011 at 1:41 AM, Bob wrote:

> So after more reading it appears templates are the way to go. Looking  
> at
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)
> 
> it appears that I want something like:
> 
> {  
> "person" : {  
> "dynamic\_templates" : [  
> {  
> "store\_generic" : {  
> "match" : "\*",  
> "mapping" : {  
> "store" : "yes"  
> }  
> }  
> }  
> ]  
> }  
> }
> 
> Unfortunately 'm having difficulty translating this example to the  
> appropriate Java API calls. In particular, it doesn't seem to specify  
> a "type" which PutIndexTemplateRequestBuilder.addMapping appears to  
> require. It also doesn't have properties, etc. I've looked at  
> simpleIndexTemplateTests in the elasticsearch integration tests which  
> showed examples when specifying types, properties, etc. but not a  
> simple case like above. I'm also confused by what "person" and  
> "dynamic\_templates" represent in the above example.
> 
> I'm sure I'm just doing something wrong, but I haven't hit on the  
> magic formula yet in my API calls. Any tips on how the above would be  
> converted to the appropriate java API call would be most appreciated.
> 
> Thanks,  
> Bob
> 
> On Apr 26, 4:29 pm, Bob [jaco...@gmail.com](mailto:jaco...@gmail.com) wrote:
> 
> > I use dynamic mapping for my index since my fields will change per  
> > document. By default I don't want any of the fields analyzed. Can I do  
> > this while still using dynamic mappings?
> > 
> > Bob

---

<div class="post-metadata">

**Author:** ![jacorob](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jacorob](https://discuss.elastic.co/u/jacorob)\
**Post date:** [April 27, 2011, 7:14pm UTC](https://discuss.elastic.co/t/default-not-analyzed/4299/4 "2011-04-27T19:14:47Z")

</div>

"When using the Java API, you just need to build the json that  
represents it."

This is what has always caused me headaches - figuring out the  
appropriate java calls that will actually create the json. In this  
case I just gave up on using XContentBuilder for the source and put  
the json in as a raw string. Not necessarily pretty, but works...

```
    PutMappingResponse pmResponse =

```

getNodeClient().admin().indices().preparePutMapping(indexName)  
.setSource("{\n" +  
" "_default_" : {\n" +  
" "dynamic\_templates" : [\n" +  
" {\n" +  
" "index\_nonanalyzed" : {\n"  
+  
" "match" : "\*",\n" +  
" "mapping" : {\n" +  
" "index" :  
"not\_analyzed"\n" +  
" }\n" +  
" }\n" +  
" }\n" +  
" ]\n" +  
" }\n" +  
"}"  
)  
.execute().actionGet();

On Apr 27, 12:13 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> person is the name of the type. What you would want to do is use dynamic template on string types, and specific the index to be not\_analyzed. When using the Java API, you just need to build the json that represents it.
> 
> On Wednesday, April 27, 2011 at 1:41 AM, Bob wrote:
> 
> > So after more reading it appears templates are the way to go. Looking  
> > at
> 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)...
> 
> > it appears that I want something like:
> 
> > {  
> > "person" : {  
> > "dynamic\_templates" : [  
> > {  
> > "store\_generic" : {  
> > "match" : "\*",  
> > "mapping" : {  
> > "store" : "yes"  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }
> 
> > Unfortunately 'm having difficulty translating this example to the  
> > appropriate Java API calls. In particular, it doesn't seem to specify  
> > a "type" which PutIndexTemplateRequestBuilder.addMapping appears to  
> > require. It also doesn't have properties, etc. I've looked at  
> > simpleIndexTemplateTests in the elasticsearch integration tests which  
> > showed examples when specifying types, properties, etc. but not a  
> > simple case like above. I'm also confused by what "person" and  
> > "dynamic\_templates" represent in the above example.
> 
> > I'm sure I'm just doing something wrong, but I haven't hit on the  
> > magic formula yet in my API calls. Any tips on how the above would be  
> > converted to the appropriate java API call would be most appreciated.
> 
> > Thanks,  
> > Bob
> 
> > On Apr 26, 4:29 pm, Bob [jaco...@gmail.com](mailto:jaco...@gmail.com) wrote:
> > 
> > > I use dynamic mapping for my index since my fields will change per  
> > > document. By default I don't want any of the fields analyzed. Can I do  
> > > this while still using dynamic mappings?
> 
> > > Bob

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 27, 2011, 7:38pm UTC](https://discuss.elastic.co/t/default-not-analyzed/4299/5 "2011-04-27T19:38:17Z")

</div>

Heya,

You can use whatever json building library you want to construct the json. The idea of the XContetBuilder is to provide a fluent API to build a json like structure, which is similar to Jackson.

By the way, regarding your template, make sure you only apply it to string types.

-shay.banon  
On Wednesday, April 27, 2011 at 10:14 PM, Bob wrote:

> "When using the Java API, you just need to build the json that  
> represents it."
> 
> This is what has always caused me headaches - figuring out the  
> appropriate java calls that will actually create the json. In this  
> case I just gave up on using XContentBuilder for the source and put  
> the json in as a raw string. Not necessarily pretty, but works...
> 
> PutMappingResponse pmResponse =  
> getNodeClient().admin().indices().preparePutMapping(indexName)  
> .setSource("{\n" +  
> " "_default_" : {\n" +  
> " "dynamic\_templates" : [\n" +  
> " {\n" +  
> " "index\_nonanalyzed" : {\n"  
> +  
> " "match" : "\*",\n" +  
> " "mapping" : {\n" +  
> " "index" :  
> "not\_analyzed"\n" +  
> " }\n" +  
> " }\n" +  
> " }\n" +  
> " ]\n" +  
> " }\n" +  
> "}"  
> )  
> .execute().actionGet();
> 
> On Apr 27, 12:13 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > person is the name of the type. What you would want to do is use dynamic template on string types, and specific the index to be not\_analyzed. When using the Java API, you just need to build the json that represents it.
> > 
> > On Wednesday, April 27, 2011 at 1:41 AM, Bob wrote:
> > 
> > > So after more reading it appears templates are the way to go. Looking  
> > > at
> > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)...
> > 
> > > it appears that I want something like:
> > 
> > > {  
> > > "person" : {  
> > > "dynamic\_templates" : [  
> > > {  
> > > "store\_generic" : {  
> > > "match" : "\*",  
> > > "mapping" : {  
> > > "store" : "yes"  
> > > }  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }
> > 
> > > Unfortunately 'm having difficulty translating this example to the  
> > > appropriate Java API calls. In particular, it doesn't seem to specify  
> > > a "type" which PutIndexTemplateRequestBuilder.addMapping appears to  
> > > require. It also doesn't have properties, etc. I've looked at  
> > > simpleIndexTemplateTests in the elasticsearch integration tests which  
> > > showed examples when specifying types, properties, etc. but not a  
> > > simple case like above. I'm also confused by what "person" and  
> > > "dynamic\_templates" represent in the above example.
> > 
> > > I'm sure I'm just doing something wrong, but I haven't hit on the  
> > > magic formula yet in my API calls. Any tips on how the above would be  
> > > converted to the appropriate java API call would be most appreciated.
> > 
> > > Thanks,  
> > > Bob
> > 
> > > On Apr 26, 4:29 pm, Bob [jaco...@gmail.com](mailto:jaco...@gmail.com) wrote:
> > > 
> > > > I use dynamic mapping for my index since my fields will change per  
> > > > document. By default I don't want any of the fields analyzed. Can I do  
> > > > this while still using dynamic mappings?
> > 
> > > > Bob

---

<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, 4:07am UTC](https://discuss.elastic.co/t/default-not-analyzed/4299/6 "2017-07-06T04:07:29Z")

</div>


