# \[0.20.4\] Java API for index creation(CreateIndexRequestBuilder) doesn't work?

**URL:** <https://discuss.elastic.co/t/0-20-4-java-api-for-index-creation-createindexrequestbuilder-doesnt-work/10759>\
**Category:** Elasticsearch\
**Created:** [February 15, 2013, 11:18pm UTC](https://discuss.elastic.co/t/0-20-4-java-api-for-index-creation-createindexrequestbuilder-doesnt-work/10759 "2013-02-15T23:18:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ross\_Martin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ross_martin/32/2488_2.png) [@Ross\_Martin](https://discuss.elastic.co/u/Ross_Martin)\
**Post date:** [February 15, 2013, 11:18pm UTC](https://discuss.elastic.co/t/0-20-4-java-api-for-index-creation-createindexrequestbuilder-doesnt-work/10759/1 "2013-02-15T23:18:15Z")

</div>

I've been having difficulties with creating custom ES indices with the Java  
API. At this point, I'm going to write-off the Java API and just use the  
REST endpoints for index management. Please let me know if you see anything  
wrong with my process below:

We create the index + settings where client is a TransportClient:  
CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(  
"files");  
builder.setSettings(settings);  
CreateIndexResponse response = builder.execute().actionGet();

settings is a String variable that contains this:  
{ "settings" : {  
"analysis" : {  
"analyzer" : {  
"filename\_search" : {  
"tokenizer" : "filename",  
"filter" : ["lowercase"]  
},  
"filename\_index" : {  
"tokenizer" : "filename",  
"filter" : ["lowercase","edge\_ngram"]  
}  
},  
"tokenizer" : {  
"filename" : {  
"pattern" : "[^\p{L}\d]+",  
"type" : "pattern"  
}  
},  
"filter" : {  
"edge\_ngram" : {  
"side" : "front",  
"max\_gram" : 20,  
"min\_gram" : 1,  
"type" : "edgeNGram"  
}  
}  
}  
}  
}

After executing this Java code, I want to verify that the index is created  
with the above settings:  
curl -XGET localhost:9200/files/\_settings?pretty=true  
{  
"files" : {  
"settings" : {  
"index.settings.analysis.filter.edge\_ngram.side" : "front",  
"index.settings.analysis.filter.edge\_ngram.max\_gram" : "20",  
"index.settings.analysis.filter.edge\_ngram.type" : "edgeNGram",  
"index.settings.analysis.tokenizer.filename.pattern" : "[^\p{L}\d]+"  
,  
"index.settings.analysis.analyzer.filename\_index.filter.1" :  
"edge\_ngram",  
"index.settings.analysis.analyzer.filename\_index.filter.0" :  
"lowercase",  
"index.settings.analysis.analyzer.filename\_index.tokenizer" :  
"filename",  
"index.settings.analysis.analyzer.filename\_search.tokenizer" :  
"filename",  
"index.settings.analysis.analyzer.filename\_search.filter.0" :  
"lowercase",  
"index.settings.analysis.filter.edge\_ngram.min\_gram" : "1",  
"index.settings.analysis.tokenizer.filename.type" : "pattern",  
"index.number\_of\_shards" : "5",  
"index.number\_of\_replicas" : "1",  
"index.version.created" : "200499"  
}  
}  
}

Looks good, right? Let's test the analyzer:  
curl -XGET  
'[http://localhost:9200/files/\_analyze?pretty=1&text=My\_first\_file\_2012.01.13.doc&analyzer=filename\_search](http://localhost:9200/files/_analyze?pretty=1&text=My_first_file_2012.01.13.doc&analyzer=filename_search)'  
{  
"error" : "ElasticSearchIllegalArgumentException[failed to find analyzer  
[filename\_search]]",  
"status" : 400  
}

Hmm, didn't work. Let's blow this index away and recreate it using the REST  
api.  
curl -XPUT '[http://localhost:9200/files/?pretty=1](http://localhost:9200/files/?pretty=1)' -d '

> {  
> "settings" : {  
> "analysis" : {  
> "analyzer" : {  
> "filename\_search" : {  
> "tokenizer" : "filename",  
> "filter" : ["lowercase"]  
> },  
> "filename\_index" : {  
> "tokenizer" : "filename",  
> "filter" : ["lowercase","edge\_ngram"]  
> }  
> },  
> "tokenizer" : {  
> "filename" : {  
> "pattern" : "[^\p{L}\d]+",  
> "type" : "pattern"  
> }  
> },  
> "filter" : {  
> "edge\_ngram" : {  
> "side" : "front",  
> "max\_gram" : 20,  
> "min\_gram" : 1,  
> "type" : "edgeNGram"  
> }  
> }  
> }  
> }  
> }  
> '  
> {  
> "ok" : true,  
> "acknowledged" : true  
> }

And we'll verify that the settings look the same as they did when we used  
the Java API, except for some values in a different order:  
curl -XGET localhost:9200/files/\_settings?pretty=true  
{  
"files" : {  
"settings" : {  
"index.analysis.analyzer.filename\_search.tokenizer" : "filename",  
"index.analysis.filter.edge\_ngram.side" : "front",  
"index.analysis.filter.edge\_ngram.type" : "edgeNGram",  
"index.analysis.analyzer.filename\_index.filter.0" : "lowercase",  
"index.analysis.analyzer.filename\_search.filter.0" : "lowercase",  
"index.analysis.analyzer.filename\_index.filter.1" : "edge\_ngram",  
"index.analysis.analyzer.filename\_index.tokenizer" : "filename",  
"index.analysis.filter.edge\_ngram.max\_gram" : "20",  
"index.analysis.filter.edge\_ngram.min\_gram" : "1",  
"index.analysis.tokenizer.filename.type" : "pattern",  
"index.analysis.tokenizer.filename.pattern" : "[^\p{L}\d]+",  
"index.number\_of\_shards" : "5",  
"index.number\_of\_replicas" : "1",  
"index.version.created" : "200499"  
}  
}  
}

Finally, we see the expected result after recreating the index with the  
REST api:

curl -XGET  
'[http://localhost:9200/files/\_analyze?pretty=1&text=My\_first\_file\_2012.01.13.doc&analyzer=filename\_search](http://localhost:9200/files/_analyze?pretty=1&text=My_first_file_2012.01.13.doc&analyzer=filename_search)'  
{  
"tokens" : [ {  
"token" : "my",  
"start\_offset" : 0,  
"end\_offset" : 2,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "first",  
"start\_offset" : 3,  
"end\_offset" : 8,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "file",  
"start\_offset" : 9,  
"end\_offset" : 13,  
"type" : "word",  
"position" : 3  
}, {  
"token" : "2012",  
"start\_offset" : 14,  
"end\_offset" : 18,  
"type" : "word",  
"position" : 4  
}, {  
"token" : "01",  
"start\_offset" : 19,  
"end\_offset" : 21,  
"type" : "word",  
"position" : 5  
}, {  
"token" : "13",  
"start\_offset" : 22,  
"end\_offset" : 24,  
"type" : "word",  
"position" : 6  
}, {  
"token" : "doc",  
"start\_offset" : 25,  
"end\_offset" : 28,  
"type" : "word",  
"position" : 7  
} ]  
}

--  
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:51am UTC](https://discuss.elastic.co/t/0-20-4-java-api-for-index-creation-createindexrequestbuilder-doesnt-work/10759/2 "2017-07-06T02:51:14Z")

</div>


