大家好我是弹性搜索的新手,我正试图处理我目前到达的错误。所以我只想要一个字段值,例如" xmldata"我在xml文件的早期进程中添加了它。 xml被格式化为json并成功加载到我的ES-Server,json文件是正确的。
这是我的代码:
Client client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
// GetResponse response = client.prepareGet("store", "xml",
// xsdid).setFields("xmldata").execute().actionGet();
GetResponse response = client.prepareGet().setIndex("store").setType("xml").setId(xsdid).setFields("xml").execute().actionGet();
String id = (String) response.getSource().get("xml");
我正在关注错误:
MapperParsingException [无法解析];嵌套:IllegalArgumentException [格式错误的内容,解析后发现额外数据:START_OBJECT];
如果您需要,我的XML看起来像这样:
<?xml version="1.0" encoding="UTF-8"?><XmlDoc><FunctionResult result="success"><Message>Processed Correct!</Message></FunctionResult>
<billing>
<billing_id>571</billing_id>
<appid>mft</appid>
<senderbtid>20041900-107</senderbtid>
<receiverbtid>20041900-40</receiverbtid>
<messagetype>M_SLSRPT</messagetype>
<messageid>83815</messageid>
<messageprops/>
<tmid>842</tmid>
<tmmsgcnt>0</tmmsgcnt>
<tmmsgtotal>1</tmmsgtotal>
<procdate>2014-12-02T03:10:15.406</procdate>
<xmldata>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48WG1sRG9jPg0KPGJpbGxpbmc+DQo8YmlsbGluZ19pZD41NzE8L2JpbGxpbmdfaWQ+DQo8YXBwaWQ+bWZ0PC9hcHBpZD4NCjxzZW5kZXJidGlkPjIwMDQxOTAwLTEwNzwvc2VuZGVyYnRpZD4NCjxyZWNlaXZlcmJ0aWQ+MjAwNDE5MDAtNDA8L3JlY2VpdmVyYnRpZD4NCjxtZXNzYWdldHlwZT5NX1NMU1JQVDwvbWVzc2FnZXR5cGU+DQo8bWVzc2FnZWlkPjgzODE1PC9tZXNzYWdlaWQ+DQo8bWVzc2FnZXByb3BzLz4NCjx0bWlkPjg0MjwvdG1pZD4NCjx0bW1zZ2NudD4wPC90bW1zZ2NudD4NCjx0bW1zZ3RvdGFsPjE8L3RtbXNndG90YWw+DQo8cHJvY2RhdGU+MjAxNC0xMi0wMlQwMzoxMDoxNS40MDY8L3Byb2NkYXRlPg0KPC9iaWxsaW5nPg0KPC9YbWxEb2M+DQoNCg==</xmldata></billing>
</XmlDoc>
请帮帮我! 感谢
答案 0 :(得分:0)
Client client = TransportClient.builder().build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
GetResponse getResponse = client.prepareGet("database", "xsd", xsdid).execute().actionGet();
Map<String, Object> source = getResponse.getSource();
像这样我得到了完整的json文件
但是有没有更好的方法来获得单一的(xmldata)?