Update mapping

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Update mapping

Frank LaRosa
Hi,

I'm trying to update a mapping via the Java API. The code appears to
work, however, when I get the mapping it hasn't changed.

Here is what my code looks like:

        IndicesAdminClient admin = client.admin().indices();
        PutMappingRequest putRequest = new PutMappingRequest(INDEX_NAME);
        putRequest.source(mapping());
        putRequest.type("_default_");
        putRequest.ignoreConflicts(true);
        PutMappingResponse response =
admin.putMapping(putRequest).actionGet(30000);
        if (response.acknowledged())
                log.info("putMapping succeeded");

Note that the funciton "mapping()" returns my mapping as an
XContentBuilder object, including the new fields and other changes I
am trying to make.

This code runs and prints the success message, but when I query the
mapping from the command line, I get the old mapping. What am I doing
wrong?
Reply | Threaded
Open this post in threaded view
|

Re: Update mapping

kimchy
Administrator
You are updating the _default_ mapping, are you saying that when you update it and then do a get, you don't get it? Can you gist a curl recreation?

On Wed, May 2, 2012 at 11:52 PM, Frank LaRosa <[hidden email]> wrote:
Hi,

I'm trying to update a mapping via the Java API. The code appears to
work, however, when I get the mapping it hasn't changed.

Here is what my code looks like:

       IndicesAdminClient admin = client.admin().indices();
       PutMappingRequest putRequest = new PutMappingRequest(INDEX_NAME);
       putRequest.source(mapping());
       putRequest.type("_default_");
       putRequest.ignoreConflicts(true);
       PutMappingResponse response =
admin.putMapping(putRequest).actionGet(30000);
       if (response.acknowledged())
               log.info("putMapping succeeded");

Note that the funciton "mapping()" returns my mapping as an
XContentBuilder object, including the new fields and other changes I
am trying to make.

This code runs and prints the success message, but when I query the
mapping from the command line, I get the old mapping. What am I doing
wrong?

Reply | Threaded
Open this post in threaded view
|

Re: Update mapping

feridcelik
I got the same issue with java api 0.19.4, and also with 0.19.3.

Putting new mappings work, but cant update. Code doesnt throw any exception or something.

PutMappingRequestBuilder rq = client.admin().indices().preparePutMapping("someIndex");
rq.setType("xxxx").setSource(TYPE_MAPPING_SOURCE);
rq.setIgnoreConflicts(true);

initial mapping source(TYPE_MAPPING_SOURCE) is something like this:
{
        "xxxx" : {
                "properties" : {
                        "someText" : {
                                "type" : "string",
                                "index" : "not_analyzed"
                        }
                }
        }
}

and im trying to update it to:
{
        "xxxx" : {
                "properties" : {
                        "someText" : {
                                "type" : "string",
                                "index" : "no"
                        }
                }
        }
}

I also tried closing index before trying to update, but it doesnt work too.

When i set ignoreConflicts,
rq.setIgnoreConflicts(false);

api throws an exception
org.elasticsearch.index.mapper.MergeMappingException: Merge failed with failures {[mapper [someText] has different index values]}

Ferid Gürbüz
Reply | Threaded
Open this post in threaded view
|

Re: Update mapping

kimchy
Administrator
You can't change the index mapping setting of a field.

On Sun, May 27, 2012 at 5:45 PM, feridcelik <[hidden email]> wrote:
I got the same issue with java api 0.19.4, and also with 0.19.3.

Putting new mappings work, but cant update. Code doesnt throw any exception
or something.

PutMappingRequestBuilder rq =
client.admin().indices().preparePutMapping("someIndex");
rq.setType("xxxx").setSource(TYPE_MAPPING_SOURCE);
rq.setIgnoreConflicts(true);

initial mapping source(TYPE_MAPPING_SOURCE) is something like this:
{
       "xxxx" : {
               "properties" : {
                       "someText" : {
                               "type" : "string",
                               "index" : "not_analyzed"
                       }
               }
       }
}

and im trying to update it to:
{
       "xxxx" : {
               "properties" : {
                       "someText" : {
                               "type" : "string",
                               "index" : "no"
                       }
               }
       }
}

I also tried closing index before trying to update, but it doesnt work too.

When i set ignoreConflicts,
rq.setIgnoreConflicts(false);

api throws an exception
org.elasticsearch.index.mapper.MergeMappingException: Merge failed with
failures {[mapper [someText] has different index values]}

Ferid Gürbüz

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Update-mapping-tp3957288p4018140.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Update mapping

Tanguy
In reply to this post by feridcelik
As far as I know if a mapping is already defined for the index/document type, you can't change any of the following setting of a field: core type, index, store, term_vector, index_analyzer or search_analyzer

-- Tanguy
Twitter: @tlrx

Le dimanche 27 mai 2012 17:45:50 UTC+2, ferid çelik a écrit :
I got the same issue with java api 0.19.4, and also with 0.19.3.

Putting new mappings work, but cant update. Code doesnt throw any exception
or something.

PutMappingRequestBuilder rq =
client.admin().indices().preparePutMapping("someIndex");
rq.setType("xxxx").setSource(TYPE_MAPPING_SOURCE);
rq.setIgnoreConflicts(true);

initial mapping source(TYPE_MAPPING_SOURCE) is something like this:
{
        "xxxx" : {
                "properties" : {
                        "someText" : {
                                "type" : "string",
                                "index" : "not_analyzed"
                        }
                }
        }
}

and im trying to update it to:
{
        "xxxx" : {
                "properties" : {
                        "someText" : {
                                "type" : "string",
                                "index" : "no"
                        }
                }
        }
}

I also tried closing index before trying to update, but it doesnt work too.

When i set ignoreConflicts,
rq.setIgnoreConflicts(false);

api throws an exception
org.elasticsearch.index.mapper.MergeMappingException: Merge failed with
failures {[mapper [someText] has different index values]}

Ferid Gürbüz

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Update-mapping-tp3957288p4018140.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Update mapping

ajasuja18
In reply to this post by kimchy
Hi Shay,

Can we change from dynamic:false to dynamic:true in case of custom mapping?

Also it would be useful to know what all can we change in the mapping 
which doesn't require the re-indexing of the older data?

Thanks in advance..!!



On Wednesday, May 30, 2012 1:55:20 AM UTC-7, kimchy wrote:
You can't change the index mapping setting of a field.

On Sun, May 27, 2012 at 5:45 PM, feridcelik <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="dVoqC3BHKqgJ">ferid...@...> wrote:
I got the same issue with java api 0.19.4, and also with 0.19.3.

Putting new mappings work, but cant update. Code doesnt throw any exception
or something.

PutMappingRequestBuilder rq =
client.admin().indices().preparePutMapping("someIndex");
rq.setType("xxxx").setSource(TYPE_MAPPING_SOURCE);
rq.setIgnoreConflicts(true);

initial mapping source(TYPE_MAPPING_SOURCE) is something like this:
{
       "xxxx" : {
               "properties" : {
                       "someText" : {
                               "type" : "string",
                               "index" : "not_analyzed"
                       }
               }
       }
}

and im trying to update it to:
{
       "xxxx" : {
               "properties" : {
                       "someText" : {
                               "type" : "string",
                               "index" : "no"
                       }
               }
       }
}

I also tried closing index before trying to update, but it doesnt work too.

When i set ignoreConflicts,
rq.setIgnoreConflicts(false);

api throws an exception
org.elasticsearch.index.mapper.MergeMappingException: Merge failed with
failures {[mapper [someText] has different index values]}

Ferid Gürbüz

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Update-mapping-tp3957288p4018140.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Update mapping

ambikaks
This post has NOT been accepted by the mailing list yet.
i am trying to update the existing elastic search with new fields but like it is said before it does not seem to update. the code runs fine.

Below is the code , can someone help me solve this?

PutMappingResponse putMappingResponse = esClient.getClient()
                                        .admin().indices().preparePutMapping(esClient.getIndex())
                                        .setType(esClient.getContextRepoType()).setSource(mapping)
                                        .execute().actionGet();
                        if (putMappingResponse.isAcknowledged()) {
                                System.out.println("putMapping succeeded");
                                status = true;



My json is as below and i converted it to the string mapping used above.

{
    "properties":{
        "CountryName":{
            "type":"string",
            "analyzer":"case_insensitive_analyzer"
        },
        "Department":{
            "type":"string",
            "analyzer":"case_insensitive_analyzer"
        },
        "Title":{
            "type":"string",
            "analyzer":"case_insensitive_analyzer"
        },
        "LocalityName":{
            "type":"string",
            "analyzer":"case_insensitive_analyzer"
        },
        "Unit":{
            "type":"string",
            "analyzer":"case_insensitive_analyzer"
        },
        "ProvinceName":{
            "type":"string",
            "analyzer":"case_insensitive_analyzer"
        },    
        "Telephone":{
            "type":"string",
            "analyzer":"case_insensitive_analyzer"
        }
    }
}