# Testable mapping definition changes

**URL:** <https://discuss.elastic.co/t/testable-mapping-definition-changes/9823>\
**Category:** Elasticsearch\
**Created:** [November 26, 2012, 11:15am UTC](https://discuss.elastic.co/t/testable-mapping-definition-changes/9823 "2012-11-26T11:15:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richo\_Healey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richo_healey/32/2572_2.png) [@Richo\_Healey](https://discuss.elastic.co/u/Richo_Healey)\
**Post date:** [November 26, 2012, 11:15am UTC](https://discuss.elastic.co/t/testable-mapping-definition-changes/9823/1 "2012-11-26T11:15:16Z")

</div>

Hello all,

I've made a start on writing some tests surrounding mapping definitions.  
The goal here is to use babushka[1] to assert that our mappings are  
correctly configured when bringing up new clusters.

I've written the start of a test here:

> <https://github.com/richo/elasticsearch/commit/834eacfa2579035b3bd4ec0e3eb3c7e99439b6f6>

But I'm unable to find any way to make the request to  
$elasticsearch/test/\_mapping internally from within the test case. It seems  
that the Client should have a method prepareGetMapping but doesn't, do I  
need to implement it? Am I missing something obvious here?

[1] [http://babushka.me](http://babushka.me)

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 26, 2012, 11:23am UTC](https://discuss.elastic.co/t/testable-mapping-definition-changes/9823/2 "2012-11-26T11:23:14Z")

</div>

You can try this: client.prepareGet("index", "type",  
"\_mapping").execute().actionGet();

HTH  
David

Le 26 novembre 2012 à 12:15, Richo Healey [healey.rich@gmail.com](mailto:healey.rich@gmail.com) a écrit :

> Hello all,
> 
> I've made a start on writing some tests surrounding mapping definitions. The  
> goal here is to use babushka[1] to assert that our mappings are correctly  
> configured when bringing up new clusters.
> 
> I've written the start of a test here:
> 
> [[WIP] Add a stub test for reproducable mappings · richo/elasticsearch@834eacf · GitHub](https://github.com/richo/elasticsearch/commit/834eacfa2579035b3bd4ec0e3eb3c7e99439b6f6)
> 
> But I'm unable to find any way to make the request to  
> $elasticsearch/test/\_mapping internally from within the test case. It seems  
> that the Client should have a method prepareGetMapping but doesn't, do I need  
> to implement it? Am I missing something obvious here?
> 
> [1] [http://babushka.me](http://babushka.me)
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Richo\_Healey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richo_healey/32/2572_2.png) [@Richo\_Healey](https://discuss.elastic.co/u/Richo_Healey)\
**Post date:** [November 26, 2012, 11:42am UTC](https://discuss.elastic.co/t/testable-mapping-definition-changes/9823/3 "2012-11-26T11:42:22Z")

</div>

Thanks very much, and also for the comment on github.

I am progressing again, but I will probably hit more hurdles. I'll update  
this thread if (when..) I get stuck again.

Richo

On Monday, 26 November 2012 22:23:20 UTC+11, David Pilato wrote:

> You can try this: client.prepareGet("index", "type",  
> "\_mapping").execute().actionGet();
> 
> HTH  
> David
> 
> Le 26 novembre 2012 à 12:15, Richo Healey \<[heale...@gmail.com](mailto:heale...@gmail.com)\<javascript:\>\>  
> a écrit :
> 
> Hello all,
> 
> I've made a start on writing some tests surrounding mapping definitions.  
> The goal here is to use babushka[1] to assert that our mappings are  
> correctly configured when bringing up new clusters.
> 
> I've written the start of a test here:
> 
> [[WIP] Add a stub test for reproducable mappings · richo/elasticsearch@834eacf · GitHub](https://github.com/richo/elasticsearch/commit/834eacfa2579035b3bd4ec0e3eb3c7e99439b6f6)
> 
> But I'm unable to find any way to make the request to  
> $elasticsearch/test/\_mapping internally from within the test case. It seems  
> that the Client should have a method prepareGetMapping but doesn't, do I  
> need to implement it? Am I missing something obvious here?
> 
> [1] [http://babushka.me](http://babushka.me)
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 27, 2012, 12:18pm UTC](https://discuss.elastic.co/t/testable-mapping-definition-changes/9823/4 "2012-11-27T12:18:39Z")

</div>

You can get mapping from the state like this:

client.admin().cluster().prepareState().execute().actionGet().state().metaData().index("test").mapping("child")

On Monday, November 26, 2012 6:15:16 AM UTC-5, Richo Healey wrote:

> Hello all,
> 
> I've made a start on writing some tests surrounding mapping definitions.  
> The goal here is to use babushka[1] to assert that our mappings are  
> correctly configured when bringing up new clusters.
> 
> I've written the start of a test here:
> 
> [[WIP] Add a stub test for reproducable mappings · richo/elasticsearch@834eacf · GitHub](https://github.com/richo/elasticsearch/commit/834eacfa2579035b3bd4ec0e3eb3c7e99439b6f6)
> 
> But I'm unable to find any way to make the request to  
> $elasticsearch/test/\_mapping internally from within the test case. It seems  
> that the Client should have a method prepareGetMapping but doesn't, do I  
> need to implement it? Am I missing something obvious here?
> 
> [1] [http://babushka.me](http://babushka.me)

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 3, 2012, 5:26pm UTC](https://discuss.elastic.co/t/testable-mapping-definition-changes/9823/5 "2012-12-03T17:26:02Z")

</div>

Thanks Igor.

In fact, my answer was incorrect as you can't GET in java a mapping using  
the prepareGet action as you can do it in CURL.  
I think that it's because the answer you get from Elasticsearch is not a  
proper GetResponse (no meta data \_index, \_type, \_id, \_version, exists).

The "strange" thing is that it does not fail but just answer that there is  
not any document matching \_mapping in index/type. Should it fail? Should I  
open an issue for that?  
I'm asking this because I searched for some minutes (hours :-/) why it was  
not working! An exception would have helped me...

FYI, test case is here: [GET \_mapping test case · GitHub](https://gist.github.com/4196419)

Cheers  
David.

Le mardi 27 novembre 2012 13:18:39 UTC+1, Igor Motov a écrit :

> You can get mapping from the state like this:
> 
> client.admin().cluster().prepareState().execute().actionGet().state().metaData().index("test").mapping("child")
> 
> On Monday, November 26, 2012 6:15:16 AM UTC-5, Richo Healey wrote:
> 
> > Hello all,
> > 
> > I've made a start on writing some tests surrounding mapping definitions.  
> > The goal here is to use babushka[1] to assert that our mappings are  
> > correctly configured when bringing up new clusters.
> > 
> > I've written the start of a test here:
> > 
> > [[WIP] Add a stub test for reproducable mappings · richo/elasticsearch@834eacf · GitHub](https://github.com/richo/elasticsearch/commit/834eacfa2579035b3bd4ec0e3eb3c7e99439b6f6)
> > 
> > But I'm unable to find any way to make the request to  
> > $elasticsearch/test/\_mapping internally from within the test case. It seems  
> > that the Client should have a method prepareGetMapping but doesn't, do I  
> > need to implement it? Am I missing something obvious here?
> > 
> > [1] [http://babushka.me](http://babushka.me)

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 5, 2012, 12:38pm UTC](https://discuss.elastic.co/t/testable-mapping-definition-changes/9823/6 "2012-12-05T12:38:43Z")

</div>

It happens because of the way REST request handlers work in elasticsearch.  
When a REST request comes, it's first evaluated against a set of registered  
handlers. The Get Mapping request handler is registered on "/mapping",  
"/{index}/\_mapping" and "/{index}/{type}/\_mapping" paths, while the Get  
request handler is registered on "/{index}/{type}/{id}" path. As you can  
see there is a certain conflict between "/{index}/{type}/\_mapping"  
and "/{index}/{type}/{id}" which is getting resolved by trying a precise  
match first and then falling back to wildcard matches. In other words, if  
elasticsearch receives a request with the "/foo/bar/\_mapping" path, it goes  
to RestGetMappingAction[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java#L59](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java#L59),  
and if it's "/foo/bar/baz", it goes to RestGetAction[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java#L47](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java#L47).  
As a result, it might create an illusion that "\_mapping" is just another  
document in the type, while in reality the mapping is stored in the cluster  
state while documents are stored in the index.

I am not sure if this is a bug. It's more like a protocol convention of  
using special paths that start with "\_" in order to make the protocol less  
verbose. Without these shortcuts the Get request would had to be mapped to  
something like "/indices/{index}/types/{type}/documents/{id}" and the Get  
Mapping request to "/indices/{index}/types/{type}/metadata/mapping". If a  
client doesn't use REST API at all, it would be strange to prohibit it from  
creating a document that with an id that just happen to match a REST API  
end point. On the other side, elasticsearch is doing this for index names.

On Monday, December 3, 2012 12:26:02 PM UTC-5, David Pilato wrote:

> Thanks Igor.
> 
> In fact, my answer was incorrect as you can't GET in java a mapping using  
> the prepareGet action as you can do it in CURL.  
> I think that it's because the answer you get from Elasticsearch is not a  
> proper GetResponse (no meta data \_index, \_type, \_id, \_version, exists).
> 
> The "strange" thing is that it does not fail but just answer that there is  
> not any document matching \_mapping in index/type. Should it fail? Should I  
> open an issue for that?  
> I'm asking this because I searched for some minutes (hours :-/) why it was  
> not working! An exception would have helped me...
> 
> FYI, test case is here: [GET \_mapping test case · GitHub](https://gist.github.com/4196419)
> 
> Cheers  
> David.
> 
> Le mardi 27 novembre 2012 13:18:39 UTC+1, Igor Motov a écrit :
> 
> > You can get mapping from the state like this:
> > 
> > client.admin().cluster().prepareState().execute().actionGet().state().metaData().index("test").mapping("child")
> > 
> > On Monday, November 26, 2012 6:15:16 AM UTC-5, Richo Healey wrote:
> > 
> > > Hello all,
> > > 
> > > I've made a start on writing some tests surrounding mapping definitions.  
> > > The goal here is to use babushka[1] to assert that our mappings are  
> > > correctly configured when bringing up new clusters.
> > > 
> > > I've written the start of a test here:
> > > 
> > > [[WIP] Add a stub test for reproducable mappings · richo/elasticsearch@834eacf · GitHub](https://github.com/richo/elasticsearch/commit/834eacfa2579035b3bd4ec0e3eb3c7e99439b6f6)
> > > 
> > > But I'm unable to find any way to make the request to  
> > > $elasticsearch/test/\_mapping internally from within the test case. It seems  
> > > that the Client should have a method prepareGetMapping but doesn't, do I  
> > > need to implement it? Am I missing something obvious here?
> > > 
> > > [1] [http://babushka.me](http://babushka.me)

--

---

<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:01am UTC](https://discuss.elastic.co/t/testable-mapping-definition-changes/9823/7 "2017-07-06T03:01:18Z")

</div>


