# How to apply default-mapping.json from classpath to an in-memory elasticsearch instance

**URL:** <https://discuss.elastic.co/t/how-to-apply-default-mapping-json-from-classpath-to-an-in-memory-elasticsearch-instance/10543>\
**Category:** Elasticsearch\
**Created:** [January 29, 2013, 4:48pm UTC](https://discuss.elastic.co/t/how-to-apply-default-mapping-json-from-classpath-to-an-in-memory-elasticsearch-instance/10543 "2013-01-29T16:48:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [January 29, 2013, 4:48pm UTC](https://discuss.elastic.co/t/how-to-apply-default-mapping-json-from-classpath-to-an-in-memory-elasticsearch-instance/10543/1 "2013-01-29T16:48:14Z")

</div>

Hi together,

if one starts a standalone elasticsearch instance and places a  
default-mapping.json inside the conf directory, those default mappings are  
applied during index creation.

How do I achieve this behavior in a java testing environment where I start  
the elasticsearch instance in memory?

The only solution I found is to apply the mapping during index creation.  
But I don't want to create the index programmatically.

Now I'm looking for a way to achieve somthing like this:

nodeBuilder.getSettings().loadFromClasspath("elasticsearch/elasticsearch.properties");  
nodeBuilder.getSettings().loadFromClasspath("elasticsearch/default-mapping.json");  
nodeBuilder.getSettings().loadFromClasspath("elasticsearch/logging.yml");

Any Ideas?

Regards, Daniel

--  
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:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [February 2, 2013, 1:38am UTC](https://discuss.elastic.co/t/how-to-apply-default-mapping-json-from-classpath-to-an-in-memory-elasticsearch-instance/10543/2 "2013-02-02T01:38:22Z")

</div>

Even when you start an embedded node it still tries to load configuration  
files from configuration directory. So, you can simply point node to the  
correct config directory by adding "path.conf" setting to the node settings  
when you build your node. Alternatively, you can specify location of  
default mapping using "index.mapper.default\_mapping\_location" setting.

On Tuesday, January 29, 2013 11:48:14 AM UTC-5, dawi wrote:

> Hi together,
> 
> if one starts a standalone elasticsearch instance and places a  
> default-mapping.json inside the conf directory, those default mappings are  
> applied during index creation.
> 
> How do I achieve this behavior in a java testing environment where I start  
> the elasticsearch instance in memory?
> 
> The only solution I found is to apply the mapping during index creation.  
> But I don't want to create the index programmatically.
> 
> Now I'm looking for a way to achieve somthing like this:
> 
> nodeBuilder.getSettings().loadFromClasspath("elasticsearch/elasticsearch.properties");
> 
> nodeBuilder.getSettings().loadFromClasspath("elasticsearch/default-mapping.json");  
> nodeBuilder.getSettings().loadFromClasspath("elasticsearch/logging.yml");
> 
> Any Ideas?
> 
> Regards, Daniel

--  
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:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [February 6, 2013, 11:05pm UTC](https://discuss.elastic.co/t/how-to-apply-default-mapping-json-from-classpath-to-an-in-memory-elasticsearch-instance/10543/3 "2013-02-06T23:05:05Z")

</div>

Hi Igor,

I am looking for a solution to load those settings from classpath for  
example to have a default-mapping.json inside a jar file.

Regards,  
Daniel

Am Samstag, 2. Februar 2013 02:38:22 UTC+1 schrieb Igor Motov:

> Even when you start an embedded node it still tries to load configuration  
> files from configuration directory. So, you can simply point node to the  
> correct config directory by adding "path.conf" setting to the node settings  
> when you build your node. Alternatively, you can specify location of  
> default mapping using "index.mapper.default\_mapping\_location" setting.
> 
> On Tuesday, January 29, 2013 11:48:14 AM UTC-5, dawi wrote:
> 
> > Hi together,
> > 
> > if one starts a standalone elasticsearch instance and places a  
> > default-mapping.json inside the conf directory, those default mappings are  
> > applied during index creation.
> > 
> > How do I achieve this behavior in a java testing environment where I  
> > start the elasticsearch instance in memory?
> > 
> > The only solution I found is to apply the mapping during index creation.  
> > But I don't want to create the index programmatically.
> > 
> > Now I'm looking for a way to achieve somthing like this:
> > 
> > nodeBuilder.getSettings().loadFromClasspath("elasticsearch/elasticsearch.properties");
> > 
> > nodeBuilder.getSettings().loadFromClasspath("elasticsearch/default-mapping.json");  
> > nodeBuilder.getSettings().loadFromClasspath("elasticsearch/logging.yml");
> > 
> > Any Ideas?
> > 
> > Regards, Daniel

--  
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:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [February 7, 2013, 12:39am UTC](https://discuss.elastic.co/t/how-to-apply-default-mapping-json-from-classpath-to-an-in-memory-elasticsearch-instance/10543/4 "2013-02-07T00:39:18Z")

</div>

It should work for classpath resources as well. When elasticsearch loads  
config resources, it tries to resolve them using file system first, but if  
it cannot find these files in the file system it tries to load them from  
classpath. Check Environment.resolveConfig[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/env/Environment.java#L170](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/env/Environment.java#L170) to  
see how it works.

On Wednesday, February 6, 2013 6:05:05 PM UTC-5, dawi wrote:

> Hi Igor,
> 
> I am looking for a solution to load those settings from classpath for  
> example to have a default-mapping.json inside a jar file.
> 
> Regards,  
> Daniel
> 
> Am Samstag, 2. Februar 2013 02:38:22 UTC+1 schrieb Igor Motov:
> 
> > Even when you start an embedded node it still tries to load configuration  
> > files from configuration directory. So, you can simply point node to the  
> > correct config directory by adding "path.conf" setting to the node settings  
> > when you build your node. Alternatively, you can specify location of  
> > default mapping using "index.mapper.default\_mapping\_location" setting.
> > 
> > On Tuesday, January 29, 2013 11:48:14 AM UTC-5, dawi wrote:
> > 
> > > Hi together,
> > > 
> > > if one starts a standalone elasticsearch instance and places a  
> > > default-mapping.json inside the conf directory, those default mappings are  
> > > applied during index creation.
> > > 
> > > How do I achieve this behavior in a java testing environment where I  
> > > start the elasticsearch instance in memory?
> > > 
> > > The only solution I found is to apply the mapping during index creation.  
> > > But I don't want to create the index programmatically.
> > > 
> > > Now I'm looking for a way to achieve somthing like this:
> > > 
> > > nodeBuilder.getSettings().loadFromClasspath("elasticsearch/elasticsearch.properties");
> > > 
> > > nodeBuilder.getSettings().loadFromClasspath("elasticsearch/default-mapping.json");  
> > > nodeBuilder.getSettings().loadFromClasspath("elasticsearch/logging.yml");
> > > 
> > > Any Ideas?
> > > 
> > > Regards, Daniel

--  
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:52am UTC](https://discuss.elastic.co/t/how-to-apply-default-mapping-json-from-classpath-to-an-in-memory-elasticsearch-instance/10543/5 "2017-07-06T02:52:40Z")

</div>


