我试图通过使用Json2Flat库将我的Elasticsearch查询响应(即Json格式)转换为CSV格式,但它无效。这是Java代码。 Query Builder的查询参数来自使用Java Servlets和Jetty Server的URL。
SearchResponse response = client.prepareSearch(index)
.setQuery(QueryBuilders.matchQuery("user", query))
.setSize(100)
.execute()
.actionGet();
System.out.println("searchKeyWord : " + response);
String doc=response.toString();
JFlat flatMe = new JFlat(doc);
//directly write the JSON document to CSV
flatMe.json2Sheet().write2csv("/home/alihas/Desktop/file.json");
//directly write the JSON document to CSV but with delimiter
flatMe.json2Sheet().write2csv("/home/alihas/Desktop/file1.json",'|');
我得到的错误是:
HTTP ERROR 500
访问/的问题。原因是:
com/google/gson/JsonElement
Caused by:
java.lang.NoClassDefFoundError: com/google/gson/JsonElement
at Elasticsearch.elasticsearch.searchKeyWord(elasticsearch.java:296)
at Elasticsearch.elasticsearch.mainMe(elasticsearch.java:98)
at Elasticsearch.QuerySelector.doGet(QuerySelector.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:530)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:426)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:931)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:361)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:867)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
at org.eclipse.jetty.server.Server.handle(Server.java:337)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:581)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1005)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:560)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:222)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:417)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:474)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:437)
at java.lang.Thread.run(Thread.java:745)
非常感谢任何帮助。