尝试设置映射时出现此错误。
压缩器检测只能在某些xcontent字节或压缩的xcontent字节
上调用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();
答案 0 :(得分:1)
您可以打印请求正文并在命令行中尝试吗?尝试打印这个:
client.admin().indices()
.preparePutMapping("mydocuments")
.setType("mytype")
.setSource(mapping)
答案 1 :(得分:0)
这是Elasticsearch 2.0吗?在2.0中,它们不再隐藏依赖关系。将所需的Jackson依赖项添加到类路径中,可能会解决错误。
答案 2 :(得分:0)
您需要先将映射对象转换为字符串
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();