Java API for mapping

In "chicken and the egg" problem you mean creating an index and put mapping
to it before any indexing has been done and the sync problem around it? The
first thing is to allow to provide mappings in the REST create index
operation.

-shay.banon

On Tue, Nov 16, 2010 at 4:34 PM, Ivan Brusic ivan_brusic@yahoo.com wrote:

Thanks for the clarification. I was concentrating on the addMapping
call in CreateIndexRequestBuilder and I couldn't figure out how to
create a CreateIndexRequestBuilder from an IndexRequestBuilder. Did
not scroll down to the putMapping method. :slight_smile:

In the end, I found the method of using files for built-in custom
mappings. This solution is even better since I can create my own roll
out with the mapping files included and skip the explicit put mapping
call on bootstrap. Awesome! However, before that I was struggling
with the REST API. Putting a mapping to the _all index had no effect
on future indexing requests. You cannot put a mapping on an index
that does not exist and an attempt to put a mapping after indexing
returned the error:

{"error":"Merge failed with failures {[mapper [value] has different
index values, mapper [value] has different store values, mapper
[value] has different index_analyzer, mapper [value] has different
search_analyzer]}"}

Built-in custom mappings work perfectly, but I was wondering, for
future reference, how to get around the chicken-and-the-egg problem
above?

Cheers,

Ivan

On Nov 15, 5:47 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

There is the putMapping API in the client#admin#indices.

On Mon, Nov 15, 2010 at 10:22 PM, Ivan Brusic ivan_bru...@yahoo.com
wrote:

BTW, I found the answer to my last question in the docs. For those
interested, yes you can use _all.

On Nov 15, 3:21 pm, Ivan Brusic ivan_bru...@yahoo.com wrote:

Perhaps I am missing something fundamental, but I cannot figure out
how to add a mapping via the Java API. I can index and query
documents, but I do not see the relevant methods in the client
interface. You have prepareIndex, prepareSearch, prepareBulk, etc..,
but I do not know which is applicable for mapping.

There is always the REST API, but I prefer to keep things in code for
version control purposes. I can rollout a new version of the server
and not have to remember to update the mappings.

If I must use the REST API, can I create a mapping at the type level
(regardless of index)?

curl -XPUT 'http://localhost:9200/_all/mytype/_mapping'-d'
{
"mytype" : {
"properties" : {
"value" : {"type" : "string", "store" : "yes", "index" :
"not_analyzed"}
}
}}

'