首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch错误: MapperParsingException:解析失败

Elasticsearch错误: MapperParsingException:解析失败
EN

Stack Overflow用户
提问于 2015-04-19 20:31:41
回答 1查看 6.4K关注 0票数 0

我想在Java中使用Apache HttpClient向Elasticsearch添加一个条目。

代码语言:javascript
复制
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://localhost:9200/index/entries/");

List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("title", "Title123"));
params.add(new BasicNameValuePair("content", "Content123"));

httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httppost);

发送请求后,Elasticsearch将使用以下错误进行响应:

org.elasticsearch.index.mapper.MapperParsingException:未能解析 由: org.elasticsearch.ElasticsearchParseException:未能从(offset=0,length=33)派生xcontent:.

我的要求似乎是无效的,但我不知道为什么。

下面是Elasticsearch的完整跟踪:

代码语言:javascript
复制
[index][0], node[LomlwFXNQl2w_hBrHGKU0Q], [P], s[STARTED]: Failed to execute [index {[index][entries][AUzTUAj4AmLRyNLK73dO], source[_na_]}]
org.elasticsearch.index.mapper.MapperParsingException: failed to parse
  at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:565)
  at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:493)
  at org.elasticsearch.index.shard.IndexShard.prepareCreate(IndexShard.java:453)
  at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:201)
  at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:515)
  at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:422)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.ElasticsearchParseException: Failed to derive xcontent from (offset=0, length=33): [116, 105, 116, 108, 101, 61, 84, 105, 116, 108, 101, 49, 50, 51, 38, 99, 111, 110, 116, 101, 110, 116, 61, 67, 111, 110, 116, 101, 110, 116, 49, 50, 51]
  at org.elasticsearch.common.xcontent.XContentFactory.xContent(XContentFactory.java:195)
  at org.elasticsearch.common.xcontent.XContentHelper.createParser(XContentHelper.java:73)
  at org.elasticsearch.common.xcontent.XContentHelper.createParser(XContentHelper.java:51)
  at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:507)
  ... 8 more

和Apache日志:

代码语言:javascript
复制
2015/04/19 22:12:59:959 CEST [DEBUG] wire - http-outgoing-0 >> "POST /index/entries/ HTTP/1.1[\r][\n]"
2015/04/19 22:12:59:962 CEST [DEBUG] wire - http-outgoing-0 >> "Content-Length: 33[\r][\n]"
2015/04/19 22:12:59:962 CEST [DEBUG] wire - http-outgoing-0 >> "Content-Type: application/x-www-form-urlencoded; charset=UTF-8[\r][\n]"
2015/04/19 22:12:59:962 CEST [DEBUG] wire - http-outgoing-0 >> "Host: localhost:9200[\r][\n]"
2015/04/19 22:12:59:963 CEST [DEBUG] wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2015/04/19 22:12:59:963 CEST [DEBUG] wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.4.1 (Java/1.8.0_40)[\r][\n]"
2015/04/19 22:12:59:963 CEST [DEBUG] wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2015/04/19 22:12:59:963 CEST [DEBUG] wire - http-outgoing-0 >> "[\r][\n]"
2015/04/19 22:12:59:963 CEST [DEBUG] wire - http-outgoing-0 >> "title=Title123&content=Content123"
2015/04/19 22:13:00:051 CEST [DEBUG] wire - http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]"
2015/04/19 22:13:00:051 CEST [DEBUG] wire - http-outgoing-0 << "Content-Type: application/json; charset=UTF-8[\r][\n]"
2015/04/19 22:13:00:051 CEST [DEBUG] wire - http-outgoing-0 << "Content-Length: 312[\r][\n]"
2015/04/19 22:13:00:052 CEST [DEBUG] wire - http-outgoing-0 << "[\r][\n]"
2015/04/19 22:13:00:052 CEST [DEBUG] wire - http-outgoing-0 << "{"error":"MapperParsingException[failed to parse]; nested: ElasticsearchParseException[Failed to derive xcontent from (offset=0, length=33): [116, 105, 116, 108, 101, 61, 84, 105, 116, 108, 101, 49, 50, 51, 38, 99, 111, 110, 116, 101, 110, 116, 61, 67, 111, 110, 116, 101, 110, 116, 49, 50, 51]]; ","status":400}"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-19 21:52:27

好吧我发现了我的错误。

我的实体不作为JSON处理。使用StringEntity起作用了:

代码语言:javascript
复制
StringEntity params = new StringEntity("{your JSON String}");
params.setContentType("application/json");
httppost.setEntity(params);
httppost.setHeader("Content-type", "application/json");
HttpResponse response = httpclient.execute(httppost);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29735483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档