# Problem in ElasticSearch Analyzer using Java API

**URL:** <https://discuss.elastic.co/t/problem-in-elasticsearch-analyzer-using-java-api/9826>\
**Category:** Elasticsearch\
**Created:** [November 26, 2012, 3:27pm UTC](https://discuss.elastic.co/t/problem-in-elasticsearch-analyzer-using-java-api/9826 "2012-11-26T15:27:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![smhdiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smhdiu/32/1808_2.png) [@smhdiu](https://discuss.elastic.co/u/smhdiu)\
**Post date:** [November 26, 2012, 3:27pm UTC](https://discuss.elastic.co/t/problem-in-elasticsearch-analyzer-using-java-api/9826/1 "2012-11-26T15:27:42Z")

</div>

Hello,

following is my java code to create index using the mappings and settings.  
however its creating the index with given name but when we run following  
command

curl -XGET '[http://localhost:9200/test/test/\_mapping](http://localhost:9200/test/test/_mapping)'

we get : {"error":"TypeMissingException[[test] type[test]  
missing]","status":404}

and also curl -XGET '[http://localhost:9200/test/\_mapping](http://localhost:9200/test/_mapping)'

gives {"test":{}}

which is neither showing the mappings nor analyzer.

`
public void createIndex(String indexName, String type) throws IOException {
```
    client.admin().indices().prepareCreate(indexName)

```
.setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
.startObject()
.startObject("mappings")
.startObject(type)
.startObject("properties")
.startObject("firstName")
.field("type", "string")
.field("search_analyzer",
"name_analyzer")
.field("index_analyzer",
"name_analyzer")
.endObject()
.startObject("email")
.field("type", "string")
.field("search_analyzer",
"email_analyzer")
.field("index_analyzer",
"email_analyzer")
.endObject()
.endObject()
.endObject()
.endObject()
.startObject("settings")
.startObject("analysis")
.startObject("analyzer")
.startObject("name_analyzer")
.field("filter",new
String[]{"standard","lowercase","asciifolding"})
.field("type","custom")
.field("tokenizer","standard")
.endObject()
.startObject("email_analyzer")
.field("type","custom")
.field("tokenizer","uax_url_email")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().toString()))
```
            .execute().actionGet();
}

```
`

problem is that it is not showing the mappings with properties and settings  
for analyzer.

please suggest

Thanks

--

---

<div class="post-metadata">

**Author:** ![smhdiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smhdiu/32/1808_2.png) [@smhdiu](https://discuss.elastic.co/u/smhdiu)\
**Post date:** [November 27, 2012, 11:13am UTC](https://discuss.elastic.co/t/problem-in-elasticsearch-analyzer-using-java-api/9826/2 "2012-11-27T11:13:17Z")

</div>

UP

On Monday, 26 November 2012 15:27:42 UTC, mohsin husen wrote:

> Hello,
> 
> following is my java code to create index using the mappings and settings.  
> however its creating the index with given name but when we run following  
> command
> 
> curl -XGET '[http://localhost:9200/test/test/\_mapping](http://localhost:9200/test/test/_mapping)'
> 
> we get : {"error":"TypeMissingException[[test] type[test]  
> missing]","status":404}
> 
> and also curl -XGET '[http://localhost:9200/test/\_mapping](http://localhost:9200/test/_mapping)'
> 
> gives {"test":{}}
> 
> which is neither showing the mappings nor analyzer.
> 
> `
> public void createIndex(String indexName, String type) throws IOException {
> ```
> client.admin().indices().prepareCreate(indexName)
> 
> ```
> .setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
> .startObject()
> .startObject("mappings")
> .startObject(type)
> .startObject("properties")
> .startObject("firstName")
> .field("type", "string")
> .field("search_analyzer",
> "name_analyzer")
> .field("index_analyzer",
> "name_analyzer")
> .endObject()
> .startObject("email")
> .field("type", "string")
> .field("search_analyzer",
> "email_analyzer")
> .field("index_analyzer",
> "email_analyzer")
> .endObject()
> .endObject()
> .endObject()
> .endObject()
> .startObject("settings")
> .startObject("analysis")
> .startObject("analyzer")
> .startObject("name_analyzer")
> .field("filter",new
> String{"standard","lowercase","asciifolding"})
> .field("type","custom")
> .field("tokenizer","standard")
> .endObject()
> .startObject("email_analyzer")
> .field("type","custom")
> .field("tokenizer","uax_url_email")
> .endObject()
> .endObject()
> .endObject()
> .endObject()
> .endObject().toString()))
> ```
> .execute().actionGet();
> }
> 
> ```
> `
> 
> problem is that it is not showing the mappings with properties and  
> settings for analyzer.
> 
> please suggest
> 
> Thanks

--

---

<div class="post-metadata">

**Author:** ![Tanguy1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tanguy1/32/1749_2.png) [@Tanguy1](https://discuss.elastic.co/u/Tanguy1)\
**Post date:** [November 27, 2012, 11:20am UTC](https://discuss.elastic.co/t/problem-in-elasticsearch-analyzer-using-java-api/9826/3 "2012-11-27T11:20:58Z")

</div>

In your code, you set mapping + settings at the settings level:

client.admin().indices().prepareCreate(indexName).setSettings(...your JSON  
with mapping and settings...)

That's why your settings and mappings are not parsed by elasticsearch.

You can try something like:

client.admin().indices().prepareCreate(indexName)

.setSettings("... your JSON settings..")

.addMapping(type, "... your mapping...")

-- Tanguy

Le lundi 26 novembre 2012 16:27:42 UTC+1, mohsin husen a écrit :

> Hello,
> 
> following is my java code to create index using the mappings and settings.  
> however its creating the index with given name but when we run following  
> command
> 
> curl -XGET '[http://localhost:9200/test/test/\_mapping](http://localhost:9200/test/test/_mapping)'
> 
> we get : {"error":"TypeMissingException[[test] type[test]  
> missing]","status":404}
> 
> and also curl -XGET '[http://localhost:9200/test/\_mapping](http://localhost:9200/test/_mapping)'
> 
> gives {"test":{}}
> 
> which is neither showing the mappings nor analyzer.
> 
> `
> public void createIndex(String indexName, String type) throws IOException {
> ```
> client.admin().indices().prepareCreate(indexName)
> 
> ```
> .setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
> .startObject()
> .startObject("mappings")
> .startObject(type)
> .startObject("properties")
> .startObject("firstName")
> .field("type", "string")
> .field("search_analyzer",
> "name_analyzer")
> .field("index_analyzer",
> "name_analyzer")
> .endObject()
> .startObject("email")
> .field("type", "string")
> .field("search_analyzer",
> "email_analyzer")
> .field("index_analyzer",
> "email_analyzer")
> .endObject()
> .endObject()
> .endObject()
> .endObject()
> .startObject("settings")
> .startObject("analysis")
> .startObject("analyzer")
> .startObject("name_analyzer")
> .field("filter",new
> String{"standard","lowercase","asciifolding"})
> .field("type","custom")
> .field("tokenizer","standard")
> .endObject()
> .startObject("email_analyzer")
> .field("type","custom")
> .field("tokenizer","uax_url_email")
> .endObject()
> .endObject()
> .endObject()
> .endObject()
> .endObject().toString()))
> ```
> .execute().actionGet();
> }
> 
> ```
> `
> 
> problem is that it is not showing the mappings with properties and  
> settings for analyzer.
> 
> please suggest
> 
> Thanks

--

---

<div class="post-metadata">

**Author:** ![smhdiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smhdiu/32/1808_2.png) [@smhdiu](https://discuss.elastic.co/u/smhdiu)\
**Post date:** [November 27, 2012, 2:33pm UTC](https://discuss.elastic.co/t/problem-in-elasticsearch-analyzer-using-java-api/9826/4 "2012-11-27T14:33:05Z")

</div>

Thanks Tanguy !  
yea i am trying now as per your suggestion.  
i was wondering like can we load mappings as well from json file like we  
are doing it with loadfromfile(setings) ?  
Thanks

Mohsin

On Monday, 26 November 2012 15:27:42 UTC, mohsin husen wrote:

> Hello,
> 
> following is my java code to create index using the mappings and settings.  
> however its creating the index with given name but when we run following  
> command
> 
> curl -XGET '[http://localhost:9200/test/test/\_mapping](http://localhost:9200/test/test/_mapping)'
> 
> we get : {"error":"TypeMissingException[[test] type[test]  
> missing]","status":404}
> 
> and also curl -XGET '[http://localhost:9200/test/\_mapping](http://localhost:9200/test/_mapping)'
> 
> gives {"test":{}}
> 
> which is neither showing the mappings nor analyzer.
> 
> `
> public void createIndex(String indexName, String type) throws IOException {
> ```
> client.admin().indices().prepareCreate(indexName)
> 
> ```
> .setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder()
> .startObject()
> .startObject("mappings")
> .startObject(type)
> .startObject("properties")
> .startObject("firstName")
> .field("type", "string")
> .field("search_analyzer",
> "name_analyzer")
> .field("index_analyzer",
> "name_analyzer")
> .endObject()
> .startObject("email")
> .field("type", "string")
> .field("search_analyzer",
> "email_analyzer")
> .field("index_analyzer",
> "email_analyzer")
> .endObject()
> .endObject()
> .endObject()
> .endObject()
> .startObject("settings")
> .startObject("analysis")
> .startObject("analyzer")
> .startObject("name_analyzer")
> .field("filter",new
> String{"standard","lowercase","asciifolding"})
> .field("type","custom")
> .field("tokenizer","standard")
> .endObject()
> .startObject("email_analyzer")
> .field("type","custom")
> .field("tokenizer","uax_url_email")
> .endObject()
> .endObject()
> .endObject()
> .endObject()
> .endObject().toString()))
> ```
> .execute().actionGet();
> }
> 
> ```
> `
> 
> problem is that it is not showing the mappings with properties and  
> settings for analyzer.
> 
> please suggest
> 
> Thanks

--

---

<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:02am UTC](https://discuss.elastic.co/t/problem-in-elasticsearch-analyzer-using-java-api/9826/5 "2017-07-06T03:02:43Z")

</div>


