# How to verify mapping is set properly or not using java?

**URL:** <https://discuss.elastic.co/t/how-to-verify-mapping-is-set-properly-or-not-using-java/6438>\
**Category:** Elasticsearch\
**Created:** [January 19, 2012, 11:59am UTC](https://discuss.elastic.co/t/how-to-verify-mapping-is-set-properly-or-not-using-java/6438 "2012-01-19T11:59:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shammi\_mishra](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@shammi\_mishra](https://discuss.elastic.co/u/shammi_mishra)\
**Post date:** [January 19, 2012, 11:59am UTC](https://discuss.elastic.co/t/how-to-verify-mapping-is-set-properly-or-not-using-java/6438/1 "2012-01-19T11:59:31Z")

</div>

Hi  
I am using java code to set mapping.  
Is there any way to check the mapping i am using is applied or not  
because even in invalid mapping setting i don't get any exception. I  
want to make it sure that mapping is applied.

Mapping :

{  
"index" : {  
"analysis" : {  
"analyzer" : {  
"index\_analyzer" : {  
"type":"custom",  
"tokenizer" : "whitespace",  
"filter" : ["lowercase", "customstopword"]  
},  
"search\_analyzer" : {  
"type":"custom",  
"tokenizer" : "whitespace",  
"filter" : ["lowercase", "customstopword"]  
}  
},  
"filter" : {  
"customstopword": {  
"type" : "stop",  
"stopwords\_path" :"c:/stopwordeng.txt" ,  
"ignore\_case":true  
}  
}  
}  
}  
}

Used java code putting Mapping:

```
	 //creating index
         CreateIndexResponse createindexresponseactionGet =

```

client.admin().indices().create(new  
CreateIndexRequest(indexName)).actionGet();

logger.info("createindexresponseactionGet::"+createindexresponseactionGet);

```
		  //putting mapping
         PutMappingResponse actionGet =

```

client.admin().indices().preparePutMapping(indexName).setType(indexType).setSource(mappingsource).execute().actionGet();  
boolean acknowledged = actionGet.getAcknowledged();  
logger.info("put mapping  
acknowledged::"+acknowledged);

Thanks

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 19, 2012, 6:31pm UTC](https://discuss.elastic.co/t/how-to-verify-mapping-is-set-properly-or-not-using-java/6438/2 "2012-01-19T18:31:56Z")

</div>

You can get the mapping back using the cluster state API. Here is how the  
REST get mapping endpoint uses it:  
[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java#L66](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java#L66)  
.

On Thu, Jan 19, 2012 at 1:59 PM, shammi mishra [mishrashammi44@gmail.com](mailto:mishrashammi44@gmail.com)wrote:

> Hi  
> I am using java code to set mapping.  
> Is there any way to check the mapping i am using is applied or not  
> because even in invalid mapping setting i don't get any exception. I  
> want to make it sure that mapping is applied.
> 
> Mapping :
> 
> {  
> "index" : {  
> "analysis" : {  
> "analyzer" : {  
> "index\_analyzer" : {  
> "type":"custom",  
> "tokenizer" : "whitespace",  
> "filter" : ["lowercase", "customstopword"]  
> },  
> "search\_analyzer" : {  
> "type":"custom",  
> "tokenizer" : "whitespace",  
> "filter" : ["lowercase", "customstopword"]  
> }  
> },  
> "filter" : {  
> "customstopword": {  
> "type" : "stop",  
> "stopwords\_path" :"c:/stopwordeng.txt" ,  
> "ignore\_case":true  
> }  
> }  
> }  
> }  
> }
> 
> Used java code putting Mapping:
> 
> ```
> //creating index
> CreateIndexResponse createindexresponseactionGet =
> 
> ```
> 
> client.admin().indices().create(new  
> CreateIndexRequest(indexName)).actionGet();
> 
> logger.info  
> ("createindexresponseactionGet::"+createindexresponseactionGet);
> 
> ```
> //putting mapping
> PutMappingResponse actionGet =
> 
> ```
> 
> client.admin().indices().preparePutMapping(indexName).setType(indexType).setSource(mappingsource).execute().actionGet();  
> boolean acknowledged = actionGet.getAcknowledged();  
> logger.info("put mapping  
> acknowledged::"+acknowledged);
> 
> 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:42am UTC](https://discuss.elastic.co/t/how-to-verify-mapping-is-set-properly-or-not-using-java/6438/3 "2017-07-06T03:42:06Z")

</div>


