我正在尝试学习如何使用logstash,redis,elasticsearch和Kibana等工具。
我已成功完成工具logstash,redis,elasticsearch和Kibana的配置。阅读日志文件,并能够将其正确插入弹性搜索。
现在我的目标是使用Java并将字符串存储到elasticsearch。我已经在同一台机器上运行了弹性搜索(Linux Ubuntu)。
使用的代码如下:
Settings settings = ImmutableSettings.settingsBuilder()
.put("client.transport.sniff", false).build();
Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("192.168.160.242", 9300));
//Convert to JSON and index
IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
.setSource(jsonBuilder()
.startObject()
.field("user", "kimchy")
.field("postDate", new Date())
.field("message", "trying out Elastic Search")
.endObject()
)
.execute()
.actionGet();
但是在使用弹性搜索控制台时,我观察到以下错误:
[2014-01-02 14:00:20,410][WARN ][transport.netty ] [Kine, Benedict] exception caught on transport layer [[id: 0xaa3df382, /**192.168.160.242:38045** :> /**192.168.160.242:9300**]], closing connection
java.io.StreamCorruptedException: invalid internal transport message format
at org.elasticsearch.transport.netty.SizeHeaderFrameDecoder.decode(SizeHeaderFrameDecoder.java:27)
at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:425)
at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)
at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:74)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
如果我遗失了什么,请告诉我?
答案 0 :(得分:0)
它非常随机的建议,但你是否设置了自定义claster名称的elasticsearch?如果是的话,可能会尝试将其添加到设置中吗?
答案 1 :(得分:0)
检查您正在使用的java客户端版本和elasticsearch服务器。
根据this指南,它们应该相同
答案 2 :(得分:0)
您可以尝试使用群集名称而不是client.transport.sniff"为假
要查看您当前的cluser_name:
curl -XGET hostname:port/_cluster/nodes?pretty=true
并使用
创建连接Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "test").build();
Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("hostname", port));