2015-11-16 51 views
0

尝试设置映射我收到此错误..弹性错误而设置映射

压缩机检测只能叫上一些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

这是与Elasticsearch 2.0 ?在2.0中,它们不再遮蔽依赖关系。将所需的Jackson依赖关系添加到您的类路径中,并且可能会解决错误。

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(); 
+0

@ user3549576你可以试试这个吗? – Val

1

您可以打印您的要求的身体和尝试在命令行?尝试打印此:

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