# Adding mapping and settings using Java API

**URL:** <https://discuss.elastic.co/t/adding-mapping-and-settings-using-java-api/13983>\
**Category:** Elasticsearch\
**Created:** [October 17, 2013, 5:39am UTC](https://discuss.elastic.co/t/adding-mapping-and-settings-using-java-api/13983 "2013-10-17T05:39:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerson\_Galang1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerson_galang1/32/2036_2.png) [@Gerson\_Galang1](https://discuss.elastic.co/u/Gerson_Galang1)\
**Post date:** [October 17, 2013, 5:39am UTC](https://discuss.elastic.co/t/adding-mapping-and-settings-using-java-api/13983/1 "2013-10-17T05:39:49Z")

</div>

Hi guys,

I'm using ES 0.90.02. I followed kimchy's advice on this similar post (  
[http://elasticsearch-users.115913.n3.nabble.com/updating-settings-and-mapping-with-java-API-td3707085.html](http://elasticsearch-users.115913.n3.nabble.com/updating-settings-and-mapping-with-java-API-td3707085.html))  
but the code I've written doesn't seem to work when the mapping file  
includes a geospatially coded attribute. Here's the code that I have  
written to create an index and add the necessary mapping and settings to  
the index.

```
URL mappingUrl = this.getClass().getResource("/test-mapping.json");
String mappingStr = FileUtils
    .readFileToString(new File(mappingUrl.toURI()));

URL settingsUrl = this.getClass().getResource("/test-settings.json");
String settingsStr = FileUtils.readFileToString(new File(settingsUrl
    .toURI()));

client.admin().indices().prepareCreate("inmemory-data-registry")
    .setSettings(settingsStr)
    .addMapping("dataset", mappingStr).execute()
    .actionGet();

```

And here's the test-mapping.json file:

{  
"properties" : {  
"dataSourceURI": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"location":{  
"type":"geo\_shape",  
"store":"yes",  
"tree":"quadtree",  
"precision":"1m"  
},  
"title" : {  
"fields" : {  
"metaphone" : {  
"type" : "string",  
"analyzer" : "name\_metaphone"  
},  
"partial" : {  
"search\_analyzer" : "full\_name",  
"index\_analyzer" : "partial\_name",  
"type" : "string"  
},  
"title" : {  
"type" : "string",  
"analyzer" : "full\_name"  
}  
},  
"type" : "multi\_field"  
}  
}  
}

And the test-settings.json file

{  
"analysis" : {  
"filter" : {  
"name\_ngrams" : {  
"side" : "front",  
"max\_gram" : 10,  
"min\_gram" : 1,  
"type" : "edgeNGram"  
},  
"name\_metaphone" : {  
"replace" : false,  
"encoder" : "metaphone",  
"type" : "phonetic"  
}  
},  
"analyzer" : {  
"full\_name" : {  
"filter" : [  
"standard",  
"lowercase",  
"asciifolding"  
],  
"type" : "custom",  
"tokenizer" : "standard"  
},  
"name\_metaphone" : {  
"filter" : [  
"name\_metaphone"  
],  
"type" : "custom",  
"tokenizer" : "standard"  
},  
"partial\_name" : {  
"filter" : [  
"standard",  
"lowercase",  
"asciifolding",  
"name\_ngrams"  
],  
"type" : "custom",  
"tokenizer" : "standard"  
}  
}  
}  
}

The problem I have is when I run a "within" bounds query on the dataset, I  
get an exception telling me that the response couldn't be deserialized. And  
if I run a curl query from the terminal, it will give me this response...

$ curl -XGET  
'[http://localhost:9200/inmemory-data-registry/dataset/\_search?pretty=true](http://localhost:9200/inmemory-data-registry/dataset/_search?pretty=true)'  
-d '{

> ```
> "query": {  
> "geo_shape" : {
> "location" : {
> "shape":{
> "type":"envelope",
> "coordinates" : [[95,-8],[161,-45]]
> }
> }
> }
> }
> 
> ```
> 
> }  
> '  
> {  
> "error" : "SearchPhaseExecutionException[Failed to execute phase [query],  
> total failure; shardFailures  
> {[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][4]:  
> SearchParseException[[inmemory-data-registry][4]: from[-1],size[-1]: Parse  
> Failure [Failed to parse source [{\n "query": { \n  
> "geo\_shape" : {\n "location" : {\n  
> "shape":{\n "type":"envelope",\n  
> "coordinates" : [[95,-8],[161,-45]]\n }\n  
> }\n }\n }\n}\n]]]; nested:  
> QueryParsingException[[inmemory-data-registry] Failed to find geo\_shape  
> field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][2]:  
> SearchParseException[[inmemory-data-registry][2]: from[-1],size[-1]: Parse  
> Failure [Failed to parse source [{\n "query": { \n  
> "geo\_shape" : {\n "location" : {\n  
> "shape":{\n "type":"envelope",\n  
> "coordinates" : [[95,-8],[161,-45]]\n }\n  
> }\n }\n }\n}\n]]]; nested:  
> QueryParsingException[[inmemory-data-registry] Failed to find geo\_shape  
> field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][0]:  
> SearchParseException[[inmemory-data-registry][0]: from[-1],size[-1]: Parse  
> Failure [Failed to parse source [{\n "query": { \n  
> "geo\_shape" : {\n "location" : {\n  
> "shape":{\n "type":"envelope",\n  
> "coordinates" : [[95,-8],[161,-45]]\n }\n  
> }\n }\n }\n}\n]]]; nested:  
> QueryParsingException[[inmemory-data-registry] Failed to find geo\_shape  
> field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][1]:  
> SearchParseException[[inmemory-data-registry][1]: from[-1],size[-1]: Parse  
> Failure [Failed to parse source [{\n "query": { \n  
> "geo\_shape" : {\n "location" : {\n  
> "shape":{\n "type":"envelope",\n  
> "coordinates" : [[95,-8],[161,-45]]\n }\n  
> }\n }\n }\n}\n]]]; nested:  
> QueryParsingException[[inmemory-data-registry] Failed to find geo\_shape  
> field [location]]; }]",  
> "status" : 500

The problem I'm seeing is that if I run the curl command below, the mapping  
process works fine and gives me back the data I've asked for

curl -X PUT -H "Content-Type: application/json" --data @mapping.json  
[http://127.0.0.1:9200/inmemory-data-registry](http://127.0.0.1:9200/inmemory-data-registry)

with mapping.json:

{  
"mappings" : {  
"dataset" : {  
"properties" : {  
"dataSourceURI": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"location":{  
"type":"geo\_shape",  
"store":"yes",  
"tree":"quadtree",  
"precision":"1m"  
},  
"title" : {  
"fields" : {  
"metaphone" : {  
"type" : "string",  
"analyzer" : "name\_metaphone"  
},  
"partial" : {  
"search\_analyzer" : "full\_name",  
"index\_analyzer" : "partial\_name",  
"type" : "string"  
},  
"title" : {  
"type" : "string",  
"analyzer" : "full\_name"  
}  
},  
"type" : "multi\_field"  
}  
}  
}  
},  
"settings": {  
"analysis" : {  
"filter" : {  
"name\_ngrams" : {  
"side" : "front",  
"max\_gram" : 10,  
"min\_gram" : 1,  
"type" : "edgeNGram"  
},  
"name\_metaphone" : {  
"replace" : false,  
"encoder" : "metaphone",  
"type" : "phonetic"  
}  
},  
"analyzer" : {  
"full\_name" : {  
"filter" : [  
"standard",  
"lowercase",  
"asciifolding"  
],  
"type" : "custom",  
"tokenizer" : "standard"  
},  
"name\_metaphone" : {  
"filter" : [  
"name\_metaphone"  
],  
"type" : "custom",  
"tokenizer" : "standard"  
},  
"partial\_name" : {  
"filter" : [  
"standard",  
"lowercase",  
"asciifolding",  
"name\_ngrams"  
],  
"type" : "custom",  
"tokenizer" : "standard"  
}  
}  
}  
}  
}

And the query response

$ curl -XGET  
'[http://localhost:9200/inmemory-data-registry/dataset/\_search?pretty=true](http://localhost:9200/inmemory-data-registry/dataset/_search?pretty=true)'  
-d '{  
"query": {  
"geo\_shape" : {  
"location" : {  
"shape":{  
"type":"envelope",  
"coordinates" : [[95,-8],[161,-45]]  
}  
}  
}  
}  
}  
'  
{  
"took" : 5,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "inmemory-data-registry",  
"\_type" : "dataset",  
"\_id" : "dataset-neworg-aurin:testdata23",  
"\_score" : 1.0, "\_source" :  
{"abstract":"finance","referenceSystemIdentifier":"EPSG:4283","location":{"type":"envelope","coordinates":[[96.8,-9.1],[159.1,-43.7]]},"geomField":"the\_geom","keyword":"lrt,  
mrt,  
train","organisation":"neworg","dataSourceURI":"datasource-aurinorg-richyrichg","type":"dataset","\_rev":"1-16e01c9a819a71b3e5eec9f2ed708320","title":"title","\_id":"dataset-neworg-aurin:testdata23","geoLevel":"sa5","name":"aurin:testdata23","key":"mykey","availability":true}  
} ]  
}  
}

Can you guys tell me if I'm doing anything wrong?

Thanks,  
Gerson

--  
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:** ![Gerson\_Galang1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerson_galang1/32/2036_2.png) [@Gerson\_Galang1](https://discuss.elastic.co/u/Gerson_Galang1)\
**Post date:** [October 17, 2013, 5:51am UTC](https://discuss.elastic.co/t/adding-mapping-and-settings-using-java-api/13983/2 "2013-10-17T05:51:00Z")

</div>

Hi guys,

I fixed the issue I reported below by editing the test-mapping.json file  
and enclosing the "properties" object inside my 'type' object

{  
"dataset": {  
"properties" : {}  
}  
}

Cheers

On Thursday, October 17, 2013 4:39:49 PM UTC+11, Gerson Galang wrote:

> Hi guys,
> 
> I'm using ES 0.90.02. I followed kimchy's advice on this similar post (  
> [http://elasticsearch-users.115913.n3.nabble.com/updating-settings-and-mapping-with-java-API-td3707085.html](http://elasticsearch-users.115913.n3.nabble.com/updating-settings-and-mapping-with-java-API-td3707085.html))  
> but the code I've written doesn't seem to work when the mapping file  
> includes a geospatially coded attribute. Here's the code that I have  
> written to create an index and add the necessary mapping and settings to  
> the index.
> 
> ```
> URL mappingUrl = this.getClass().getResource("/test-mapping.json");
> String mappingStr = FileUtils
> .readFileToString(new File(mappingUrl.toURI()));
> 
> URL settingsUrl = this.getClass().getResource("/test-settings.json");
> String settingsStr = FileUtils.readFileToString(new File(settingsUrl
> .toURI()));
> 
> client.admin().indices().prepareCreate("inmemory-data-registry")
> .setSettings(settingsStr)
> .addMapping("dataset", mappingStr).execute()
> .actionGet();
> 
> ```
> 
> And here's the test-mapping.json file:
> 
> {  
> "properties" : {  
> "dataSourceURI": {  
> "type": "string",  
> "index": "not\_analyzed"  
> },  
> "location":{  
> "type":"geo\_shape",  
> "store":"yes",  
> "tree":"quadtree",  
> "precision":"1m"  
> },  
> "title" : {  
> "fields" : {  
> "metaphone" : {  
> "type" : "string",  
> "analyzer" : "name\_metaphone"  
> },  
> "partial" : {  
> "search\_analyzer" : "full\_name",  
> "index\_analyzer" : "partial\_name",  
> "type" : "string"  
> },  
> "title" : {  
> "type" : "string",  
> "analyzer" : "full\_name"  
> }  
> },  
> "type" : "multi\_field"  
> }  
> }  
> }
> 
> And the test-settings.json file
> 
> {  
> "analysis" : {  
> "filter" : {  
> "name\_ngrams" : {  
> "side" : "front",  
> "max\_gram" : 10,  
> "min\_gram" : 1,  
> "type" : "edgeNGram"  
> },  
> "name\_metaphone" : {  
> "replace" : false,  
> "encoder" : "metaphone",  
> "type" : "phonetic"  
> }  
> },  
> "analyzer" : {  
> "full\_name" : {  
> "filter" : [  
> "standard",  
> "lowercase",  
> "asciifolding"  
> ],  
> "type" : "custom",  
> "tokenizer" : "standard"  
> },  
> "name\_metaphone" : {  
> "filter" : [  
> "name\_metaphone"  
> ],  
> "type" : "custom",  
> "tokenizer" : "standard"  
> },  
> "partial\_name" : {  
> "filter" : [  
> "standard",  
> "lowercase",  
> "asciifolding",  
> "name\_ngrams"  
> ],  
> "type" : "custom",  
> "tokenizer" : "standard"  
> }  
> }  
> }  
> }
> 
> The problem I have is when I run a "within" bounds query on the dataset, I  
> get an exception telling me that the response couldn't be deserialized. And  
> if I run a curl query from the terminal, it will give me this response...
> 
> $ curl -XGET '  
> [http://localhost:9200/inmemory-data-registry/dataset/\_search?pretty=true](http://localhost:9200/inmemory-data-registry/dataset/_search?pretty=true)'  
> -d '{
> 
> > ```
> > "query": {  
> > "geo_shape" : {
> > "location" : {
> > "shape":{
> > "type":"envelope",
> > "coordinates" : [[95,-8],[161,-45]]
> > }
> > }
> > }
> > }
> > 
> > ```
> > 
> > }  
> > '  
> > {  
> > "error" : "SearchPhaseExecutionException[Failed to execute phase  
> > [query], total failure; shardFailures  
> > {[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][4]:  
> > SearchParseException[[inmemory-data-registry][4]: from[-1],size[-1]: Parse  
> > Failure [Failed to parse source [{\n "query": { \n  
> > "geo\_shape" : {\n "location" : {\n  
> > "shape":{\n "type":"envelope",\n  
> > "coordinates" : [[95,-8],[161,-45]]\n }\n  
> > }\n }\n }\n}\n]]]; nested:  
> > QueryParsingException[[inmemory-data-registry] Failed to find geo\_shape  
> > field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][2]:  
> > SearchParseException[[inmemory-data-registry][2]: from[-1],size[-1]: Parse  
> > Failure [Failed to parse source [{\n "query": { \n  
> > "geo\_shape" : {\n "location" : {\n  
> > "shape":{\n "type":"envelope",\n  
> > "coordinates" : [[95,-8],[161,-45]]\n }\n  
> > }\n }\n }\n}\n]]]; nested:  
> > QueryParsingException[[inmemory-data-registry] Failed to find geo\_shape  
> > field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][0]:  
> > SearchParseException[[inmemory-data-registry][0]: from[-1],size[-1]: Parse  
> > Failure [Failed to parse source [{\n "query": { \n  
> > "geo\_shape" : {\n "location" : {\n  
> > "shape":{\n "type":"envelope",\n  
> > "coordinates" : [[95,-8],[161,-45]]\n }\n  
> > }\n }\n }\n}\n]]]; nested:  
> > QueryParsingException[[inmemory-data-registry] Failed to find geo\_shape  
> > field [location]]; }{[tSWUhOGTQdy9pmRZs0Mebw][inmemory-data-registry][1]:  
> > SearchParseException[[inmemory-data-registry][1]: from[-1],size[-1]: Parse  
> > Failure [Failed to parse source [{\n "query": { \n  
> > "geo\_shape" : {\n "location" : {\n  
> > "shape":{\n "type":"envelope",\n  
> > "coordinates" : [[95,-8],[161,-45]]\n }\n  
> > }\n }\n }\n}\n]]]; nested:  
> > QueryParsingException[[inmemory-data-registry] Failed to find geo\_shape  
> > field [location]]; }]",  
> > "status" : 500
> 
> The problem I'm seeing is that if I run the curl command below, the  
> mapping process works fine and gives me back the data I've asked for
> 
> curl -X PUT -H "Content-Type: application/json" --data @mapping.json  
> [http://127.0.0.1:9200/inmemory-data-registry](http://127.0.0.1:9200/inmemory-data-registry)
> 
> with mapping.json:
> 
> {  
> "mappings" : {  
> "dataset" : {  
> "properties" : {  
> "dataSourceURI": {  
> "type": "string",  
> "index": "not\_analyzed"  
> },  
> "location":{  
> "type":"geo\_shape",  
> "store":"yes",  
> "tree":"quadtree",  
> "precision":"1m"  
> },  
> "title" : {  
> "fields" : {  
> "metaphone" : {  
> "type" : "string",  
> "analyzer" : "name\_metaphone"  
> },  
> "partial" : {  
> "search\_analyzer" : "full\_name",  
> "index\_analyzer" : "partial\_name",  
> "type" : "string"  
> },  
> "title" : {  
> "type" : "string",  
> "analyzer" : "full\_name"  
> }  
> },  
> "type" : "multi\_field"  
> }  
> }  
> }  
> },  
> "settings": {  
> "analysis" : {  
> "filter" : {  
> "name\_ngrams" : {  
> "side" : "front",  
> "max\_gram" : 10,  
> "min\_gram" : 1,  
> "type" : "edgeNGram"  
> },  
> "name\_metaphone" : {  
> "replace" : false,  
> "encoder" : "metaphone",  
> "type" : "phonetic"  
> }  
> },  
> "analyzer" : {  
> "full\_name" : {  
> "filter" : [  
> "standard",  
> "lowercase",  
> "asciifolding"  
> ],  
> "type" : "custom",  
> "tokenizer" : "standard"  
> },  
> "name\_metaphone" : {  
> "filter" : [  
> "name\_metaphone"  
> ],  
> "type" : "custom",  
> "tokenizer" : "standard"  
> },  
> "partial\_name" : {  
> "filter" : [  
> "standard",  
> "lowercase",  
> "asciifolding",  
> "name\_ngrams"  
> ],  
> "type" : "custom",  
> "tokenizer" : "standard"  
> }  
> }  
> }  
> }  
> }
> 
> And the query response
> 
> $ curl -XGET '  
> [http://localhost:9200/inmemory-data-registry/dataset/\_search?pretty=true](http://localhost:9200/inmemory-data-registry/dataset/_search?pretty=true)'  
> -d '{  
> "query": {  
> "geo\_shape" : {  
> "location" : {  
> "shape":{  
> "type":"envelope",  
> "coordinates" : [[95,-8],[161,-45]]  
> }  
> }  
> }  
> }  
> }  
> '  
> {  
> "took" : 5,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "inmemory-data-registry",  
> "\_type" : "dataset",  
> "\_id" : "dataset-neworg-aurin:testdata23",  
> "\_score" : 1.0, "\_source" :  
> {"abstract":"finance","referenceSystemIdentifier":"EPSG:4283","location":{"type":"envelope","coordinates":[[96.8,-9.1],[159.1,-43.7]]},"geomField":"the\_geom","keyword":"lrt,  
> mrt,  
> train","organisation":"neworg","dataSourceURI":"datasource-aurinorg-richyrichg","type":"dataset","\_rev":"1-16e01c9a819a71b3e5eec9f2ed708320","title":"title","\_id":"dataset-neworg-aurin:testdata23","geoLevel":"sa5","name":"aurin:testdata23","key":"mykey","availability":true}  
> } ]  
> }  
> }
> 
> Can you guys tell me if I'm doing anything wrong?
> 
> Thanks,  
> Gerson

--  
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:11am UTC](https://discuss.elastic.co/t/adding-mapping-and-settings-using-java-api/13983/3 "2017-07-06T02:11:59Z")

</div>


