user3549576
user3549576

Reputation: 307

elastic error while setting mapping

I am getting this error while trying to set mapping..

Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes

XContentBuilder mapping = XContentFactory.jsonBuilder()
                    .startObject("mydocuments")
                    .startObject("mytype")
                    .startObject("properties")
                    .startObject("blob_field")
                    .field("type", "string")
                    .field("index", "not_analyzed")
                    .endObject()
                    .endObject()
                    .endObject()
                    .endObject();
            PutMappingResponse putMappingResponse = client.admin().indices()
                    .preparePutMapping("mydocuments")
                    .setType("mytype")
                    .setSource(mapping)
                    .execute().actionGet();

Upvotes: 0

Views: 2618

Answers (3)

citymonkeymao
citymonkeymao

Reputation: 141

Could you print your request body and try it in command line? Try to print this:

client.admin().indices()
                .preparePutMapping("mydocuments")
                .setType("mytype")
                .setSource(mapping)

Upvotes: 1

Val
Val

Reputation: 217514

You need to convert your mapping object to a string first

XContentBuilder mapping = XContentFactory.jsonBuilder()
                .startObject("mydocuments")
                .startObject("mytype")
                .startObject("properties")
                .startObject("blob_field")
                .field("type", "string")
                .field("index", "not_analyzed")
                .endObject()
                .endObject()
                .endObject()
                .endObject();

        PutMappingResponse putMappingResponse = client.admin().indices()
                .preparePutMapping("mydocuments")
                .setType("mytype")
                .setSource(mapping.string())      <---- transform to string
                .execute().actionGet();

Upvotes: 0

hudsonb
hudsonb

Reputation: 2294

Is this with Elasticsearch 2.0? In 2.0 they no longer shade dependencies. Add the required Jackson dependencies to your classpath and the error may be resolved.

Upvotes: 0

Related Questions