# Constructing mappings (apologies for repost)

**URL:** <https://discuss.elastic.co/t/constructing-mappings-apologies-for-repost/9239>\
**Category:** Elasticsearch\
**Created:** [October 4, 2012, 12:16pm UTC](https://discuss.elastic.co/t/constructing-mappings-apologies-for-repost/9239 "2012-10-04T12:16:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MyHeadHurts](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MyHeadHurts](https://discuss.elastic.co/u/MyHeadHurts)\
**Post date:** [October 4, 2012, 12:16pm UTC](https://discuss.elastic.co/t/constructing-mappings-apologies-for-repost/9239/1 "2012-10-04T12:16:53Z")

</div>

_Hi, my apologies for the repost - the last one was posted only half  
written and I cannot work out how to delete it_

In my elasticsearch.yml file am trying to implement some mapping where one  
field belonging to one type is indexed using a different analyzer to the  
rest.

At present I have the following structure in my elasticsearch.yml file:

# Index Settings

index:  
bookshelf:  
types:  
book:  
mappings:  
title: {analyzer: customAnalyzer}  
analysis:  
analyzer:  
# set standard analyzer with no stop words as the default for both  
indexing and searching  
default:  
type: standard  
stopwords: _none_  
# set custom analyser to provide a more detailed search result  
customAnalyzer:  
type: custom  
tokenizer: nGramTokenizer  
filter: [lowercase,stopWordsFilter,asciifolding]  
tokenizer:  
nGramTokenizer:  
type: nGram  
min\_gram: 1  
max\_gram: 2  
filter:  
nGramFilter:  
type: nGram  
min\_gram: 1  
max\_gram: 2  
stopWordsFilter:  
type: stop  
stopwords: _none_

This does not apply the custom analyzer to the title field, so I was hoping  
someone may be able to point me in the right direction for applying custom  
analyzers to individual fields?

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 4, 2012, 1:01pm UTC](https://discuss.elastic.co/t/constructing-mappings-apologies-for-repost/9239/2 "2012-10-04T13:01:42Z")

</div>

If you are using Java you don't have to use an yml file. You can, but you don't  
have to.

If you are using Spring, you can have a look at the ES spring factory project:  
[GitHub - dadoonet/spring-elasticsearch: Spring factories for elasticsearch](https://github.com/dadoonet/spring-elasticsearch)  
[https://github.com/dadoonet/spring-elasticsearch](https://github.com/dadoonet/spring-elasticsearch)  
If not, there is different ways of creating index and mappings in Java.

You can have a look here to see how I'm doing this by reading a json mapping  
file:  
[https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L616](https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L616)  
[https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L616](https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L616)

You can also use XContent objects provided by ES to build your mappings in Java:  
[https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/RssRiverTest.java#L14](https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/RssRiverTest.java#L14)  
[https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/RssRiverTest.java#L14](https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/RssRiverTest.java#L14)

Using this object is described here:  
[https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/AbstractRssRiverTest.java#L98](https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/AbstractRssRiverTest.java#L98)  
[https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/AbstractRssRiverTest.java#L98](https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/AbstractRssRiverTest.java#L98)

node . client (). admin (). indices ()  
. preparePutMapping ("yourindex" )  
. setType ( "yourtype" )  
. setSource ( mapping ())  
. execute (). actionGet ();

I hope this could help you

David.

Le 4 octobre 2012 à 14:16, My Head Hurts [mathieson10@gmail.com](mailto:mathieson10@gmail.com) a écrit :

> Hi, my apologies for the repost - the last one was posted only half written  
> and I cannot work out how to delete it
> 
> In my elasticsearch.yml file am trying to implement some mapping where one  
> field belonging to one type is indexed using a different analyzer to the rest.
> 
> At present I have the following structure in my elasticsearch.yml file:
> 
> # Index Settings
> 
> index :  
> bookshelf :  
> types :  
> book :  
> mappings :  
> title : { analyzer : customAnalyzer }  
> analysis :  
> analyzer :  
> # set standard analyzer with no stop words as the default for both  
> indexing and searching  
> default :  
> type : standard  
> stopwords : _none_  
> # set custom analyser to provide a more detailed search result  
> customAnalyzer :  
> type : custom  
> tokenizer : nGramTokenizer  
> filter : [lowercase , stopWordsFilter , asciifolding]  
> tokenizer :  
> nGramTokenizer :  
> type : nGram  
> min\_gram : 1  
> max\_gram : 2  
> filter :  
> nGramFilter :  
> type : nGram  
> min\_gram : 1  
> max\_gram : 2  
> stopWordsFilter :  
> type : stop  
> stopwords : _none_
> 
> This does not apply the custom analyzer to the title field, so I was hoping  
> someone may be able to point me in the right direction for applying custom  
> analyzers to individual fields?
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![MyHeadHurts](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MyHeadHurts](https://discuss.elastic.co/u/MyHeadHurts)\
**Post date:** [October 4, 2012, 1:57pm UTC](https://discuss.elastic.co/t/constructing-mappings-apologies-for-repost/9239/3 "2012-10-04T13:57:11Z")

</div>

Thanks David, I am not using spring so I shall look into your code a little  
more if you do not mind.

I am sure I will find the information very helpful, so thank you.

On Thursday, 4 October 2012 15:01:55 UTC+2, David Pilato wrote:

> If you are using Java you don't have to use an yml file. You can, but  
> you don't have to.
> 
> If you are using Spring, you can have a look at the ES spring factory  
> project: [GitHub - dadoonet/spring-elasticsearch: Spring factories for elasticsearch](https://github.com/dadoonet/spring-elasticsearch)  
> If not, there is different ways of creating index and mappings in Java.
> 
> You can have a look here to see how I'm doing this by reading a json  
> mapping file:  
> [https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L616](https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L616)
> 
> You can also use XContent objects provided by ES to build your mappings  
> in Java:  
> [https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/RssRiverTest.java#L14](https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/RssRiverTest.java#L14)
> 
> Using this object is described here:  
> [https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/AbstractRssRiverTest.java#L98](https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/AbstractRssRiverTest.java#L98)
> 
> node . client (). admin (). indices ()  
> . preparePutMapping ("yourindex" )  
> . setType ( "yourtype" )  
> . setSource ( mapping ())  
> . execute (). actionGet ();
> 
> I hope this could help you
> 
> David.
> 
> Le 4 octobre 2012 à 14:16, My Head Hurts \<[mathi...@gmail.com](mailto:mathi...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> _Hi, my apologies for the repost - the last one was posted only half  
> written and I cannot work out how to delete it_
> 
> In my elasticsearch.yml file am trying to implement some mapping where one  
> field belonging to one type is indexed using a different analyzer to the  
> rest.
> 
> At present I have the following structure in my elasticsearch.yml file:
> 
> # Index Settings
> 
> index :  
> bookshelf :  
> types :  
> book :  
> mappings :  
> title : { analyzer : customAnalyzer }  
> analysis :  
> analyzer :  
> # set standard analyzer with no stop words as the default for both  
> indexing and searching  
> default :  
> type : standard  
> stopwords : _none_  
> # set custom analyser to provide a more detailed search result  
> customAnalyzer :  
> type : custom  
> tokenizer : nGramTokenizer  
> filter : [lowercase , stopWordsFilter , asciifolding]  
> tokenizer :  
> nGramTokenizer :  
> type : nGram  
> min\_gram : 1  
> max\_gram : 2  
> filter :  
> nGramFilter :  
> type : nGram  
> min\_gram : 1  
> max\_gram : 2  
> stopWordsFilter :  
> type : stop  
> stopwords : _none_
> 
> This does not apply the custom analyzer to the title field, so I was  
> hoping someone may be able to point me in the right direction for applying  
> custom analyzers to individual fields?
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 4, 2012, 2:48pm UTC](https://discuss.elastic.co/t/constructing-mappings-apologies-for-repost/9239/4 "2012-10-04T14:48:45Z")

</div>

Yes go ahead. That's why i gave you some pointers. Feel free to ask.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 4 oct. 2012 à 15:57, My Head Hurts [mathieson10@gmail.com](mailto:mathieson10@gmail.com) a écrit :

> Thanks David, I am not using spring so I shall look into your code a little more if you do not mind.
> 
> I am sure I will find the information very helpful, so thank you.
> 
> On Thursday, 4 October 2012 15:01:55 UTC+2, David Pilato wrote:  
> If you are using Java you don't have to use an yml file. You can, but you don't have to.
> 
> If you are using Spring, you can have a look at the ES spring factory project: [GitHub - dadoonet/spring-elasticsearch: Spring factories for elasticsearch](https://github.com/dadoonet/spring-elasticsearch)  
> If not, there is different ways of creating index and mappings in Java.
> 
> You can have a look here to see how I'm doing this by reading a json mapping file: [https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L616](https://github.com/dadoonet/spring-elasticsearch/blob/master/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java#L616)
> 
> You can also use XContent objects provided by ES to build your mappings in Java: [https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/RssRiverTest.java#L14](https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/RssRiverTest.java#L14)
> 
> Using this object is described here: [https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/AbstractRssRiverTest.java#L98](https://github.com/dadoonet/rssriver/blob/master/src/test/java/org/elasticsearch/river/rss/AbstractRssRiverTest.java#L98)
> 
> node . client (). admin (). indices ()  
> . preparePutMapping ("yourindex" )  
> . setType ( "yourtype" )  
> . setSource ( mapping ())  
> . execute (). actionGet ();
> 
> I hope this could help you
> 
> David.
> 
> Le 4 octobre 2012 à 14:16, My Head Hurts [mathi...@gmail.com](mailto:mathi...@gmail.com) a écrit :
> 
> > Hi, my apologies for the repost - the last one was posted only half written and I cannot work out how to delete it
> > 
> > In my elasticsearch.yml file am trying to implement some mapping where one field belonging to one type is indexed using a different analyzer to the rest.
> > 
> > At present I have the following structure in my elasticsearch.yml file:
> > 
> > # Index Settings
> > 
> > index :  
> > bookshelf :  
> > types :  
> > book :  
> > mappings :  
> > title : { analyzer : customAnalyzer }  
> > analysis :  
> > analyzer :  
> > # set standard analyzer with no stop words as the default for both indexing and searching  
> > default :  
> > type : standard  
> > stopwords : _none_  
> > # set custom analyser to provide a more detailed search result  
> > customAnalyzer :  
> > type : custom  
> > tokenizer : nGramTokenizer  
> > filter : [lowercase , stopWordsFilter , asciifolding]  
> > tokenizer :  
> > nGramTokenizer :  
> > type : nGram  
> > min\_gram : 1  
> > max\_gram : 2  
> > filter :  
> > nGramFilter :  
> > type : nGram  
> > min\_gram : 1  
> > max\_gram : 2  
> > stopWordsFilter :  
> > type : stop  
> > stopwords : _none_
> > 
> > This does not apply the custom analyzer to the title field, so I was hoping someone may be able to point me in the right direction for applying custom analyzers to individual fields?
> > 
> > --
> 
> ## -- David Pilato [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/) [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/) Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<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:10am UTC](https://discuss.elastic.co/t/constructing-mappings-apologies-for-repost/9239/5 "2017-07-06T03:10:08Z")

</div>


