Testable mapping definition changes

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:

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

--

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 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:

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

--

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

--

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<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:

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

--

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

--

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:

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

--

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: 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:

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

--

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 RestGetMappingActionhttps://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 RestGetActionhttps://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: 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:

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

--