# Failed to put mappings on indices while using java

**URL:** <https://discuss.elastic.co/t/failed-to-put-mappings-on-indices-while-using-java/21030>\
**Category:** Elasticsearch\
**Created:** [December 2, 2014, 12:15pm UTC](https://discuss.elastic.co/t/failed-to-put-mappings-on-indices-while-using-java/21030 "2014-12-02T12:15:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephen\_maina](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@stephen\_maina](https://discuss.elastic.co/u/stephen_maina)\
**Post date:** [December 2, 2014, 12:15pm UTC](https://discuss.elastic.co/t/failed-to-put-mappings-on-indices-while-using-java/21030/1 "2014-12-02T12:15:27Z")

</div>

Hi,

Full disclosure im a newb at this:

I have been trying to create an index using the below code:  
private boolean createIndices( ) {

String indexName="279"  
String typeName="badge\_type";  
String mapping={"badge\_type": {"\_type":{"store":"true"},"

- ""\_index":{"enabled":"true"},"
- ""\_id":{"path":"badge\_type\_id"},"
- ""dynamic":"strict","
- ""properties":{  
"badge\_type\_id":{"type":"string","store":"true","index":"not\_analyzed"},"
- 

""name":{"type":"string","store":"true","index\_analyzer":"autocomplete","search\_analyzer":"standard"},"

- ""description":{"type":"string","store":"true"} "
- " } } };  
try {  
if (!NodeOperation.INSTANCE.getNode().client().admin().indices()  
.prepareExists(indexName).execute().actionGet().isExists()) {  
System.out.println("index does not exist, create it and : "
- indexName);  
log.trace("CREATE INDEX: " + indexName);  
String settings = "{"aliases": { "
- ""content": {}, "school": {}},"
- ""settings":{"
- ""index":{"
- """+indexName+"":{"
- ""analysis":{"analyzer" : [{"
- ""autocomplete" : { "
- ""type" :"custom","
- ""tokenizer":"keyword","
- ""filter":["lowercase", "autocomplete\_filter"] } "
- "},{"
- ""email\_custom" : { "
- ""type" :"custom","
- ""tokenizer":"uax\_url\_email","
- ""filter":["lowercase", "autocomplete\_filter"] } "
- "}],"filter":"
- "{"autocomplete\_filter":{ "type" :"edge\_ngram","
- ""min\_gram":"2"," + ""max\_gram":20" + " }"
- " }" + " } " + "}}}}";

CreateIndexRequestBuilder irb = NodeOperation.INSTANCE  
.getNode().client().admin().indices()  
.prepareCreate(indexName).setSource(settings);  
irb.execute().actionGet();

}

if (!isTypeExist(indexName, typeName)) {  
System.out  
.println("type does not exist create it: " + typeName);  
PutMappingResponse res = NodeOperation.INSTANCE.getNode()  
.client().admin().indices()  
.preparePutMapping(indexName).setType(typeName)  
.setSource(mapping).setIndices(indexName).execute()  
.actionGet();  
return res.isAcknowledged();  
} else {  
return true;  
}  
} catch (Exception e) {  
e.getMessage();  
}  
return false;  
}

the index is created with the following setings:  
{

"279" : {  
"settings" : {  
"index" : {  
"settings" : {  
"analysis" : {  
"filter" : {  
"autocomplete\_filter" : {  
"type" : "edge\_ngram",  
"min\_gram" : "2",  
"max\_gram" : "20"  
}  
},  
"analyzer" : [ {  
"autocomplete" : {  
"filter" : ["lowercase", "autocomplete\_filter"],  
"type" : "custom",  
"tokenizer" : "keyword"  
}  
}, {  
"email\_custom" : {  
"type" : "custom",  
"filter" : ["lowercase", "autocomplete\_filter"],  
"tokenizer" : "uax\_url\_email"  
}  
} ]  
}  
},  
"number\_of\_shards" : "5",  
"number\_of\_replicas" : "1",  
"version" : {  
"created" : "1030499"  
},  
"uuid" : "T4a3\_p3GSkKpui5zKhfSqQ"  
}  
}  
}  
}

but mapping cannot be added to the type, i get the following error:  
[2014-12-02 15:11:32,828][INFO][cluster.metadata] [War Eagle]  
[279] creating index, cause [api], shards [5]/[1], mappings []  
[2014-12-02 15:11:34,229][DEBUG][action.admin.indices.mapping.put] [War  
Eagle] failed to put mappings on indices [[279]], type [badge\_type]  
org.elasticsearch.index.mapper.MapperParsingException: Analyzer  
[autocomplete] not found for field [name]  
at  
org.elasticsearch.index.mapper.core.TypeParsers.parseField(TypeParsers.java:220)  
at  
org.elasticsearch.index.mapper.core.StringFieldMapper$TypeParser.parse(StringFieldMapper.java:153)  
at  
org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseProperties(ObjectMapper.java:289)  
at  
org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseObjectOrDocumentTypeProperties(ObjectMapper.java:217)  
at  
org.elasticsearch.index.mapper.object.RootObjectMapper$TypeParser.parse(RootObjectMapper.java:136)  
at  
org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:209)  
at  
org.elasticsearch.index.mapper.DocumentMapperParser.parseCompressed(DocumentMapperParser.java:190)  
at  
org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:440)  
at  
org.elasticsearch.cluster.metadata.MetaDataMappingService$4.execute(MetaDataMappingService.java:503)  
at  
org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:328)  
at  
org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:153)  
at  
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
at java.lang.Thread.run(Thread.java:745)

any help to finding out where im going wrong will be greatly appreciated.

Thanks in advance.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b33ab998-935c-4cb7-ba99-35106b9f7c55%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b33ab998-935c-4cb7-ba99-35106b9f7c55%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![stephen\_maina](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@stephen\_maina](https://discuss.elastic.co/u/stephen_maina)\
**Post date:** [December 2, 2014, 2:39pm UTC](https://discuss.elastic.co/t/failed-to-put-mappings-on-indices-while-using-java/21030/2 "2014-12-02T14:39:02Z")

</div>

i found my error, it was in the JSON this is the format that it should have:  
{

```
      "settings":{
          "index":{
     "analysis": {
        "filter": {
           "autocomplete_filter": {
              "type": "edge_ngram",
              "min_gram": "2",
              "max_gram": "20"
           }
        },
        "analyzer": {
              "auto_complete": {
                 "type": "custom",
                 "tokenizer": "keyword",
                 "filter": [
                    "lowercase",
                    "autocomplete_filter"
                 ]
              }
           ,
           
              "email_custom": {
                 "type": "custom",
                 "tokenizer": "uax_url_email",
                 "filter": [
                    "lowercase",
                    "autocomplete_filter"
                 ]
              }
     }
        
     }

```

}  
}  
}

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a912c56a-3983-4572-9c7a-683b77ca663e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a912c56a-3983-4572-9c7a-683b77ca663e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:46am UTC](https://discuss.elastic.co/t/failed-to-put-mappings-on-indices-while-using-java/21030/3 "2017-07-06T00:46:36Z")

</div>


