ElasticSearch - 无法读取请求数据 [英] ElasticSearch - failed to read requesting data

查看:192
本文介绍了ElasticSearch - 无法读取请求数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面这个来源:

弹性搜索示例

和我创建了一块code的:

and I created the piece of code:

import static org.elasticsearch.node.NodeBuilder.nodeBuilder;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;

public class ElasticSearchAPI {

    public static void main(String[] args) {

        Node node = nodeBuilder().clusterName("yourclustername").node();
        Client client = node.client();

        client.prepareIndex("kodcucom", "article", "1")
                .setSource(
                        putJsonDocument(
                                "ElasticSearch: Java API",
                                "ElasticSearch provides the Java API, all operations "
                                        + "can be executed asynchronously using a client object.",
                                new Date(), new String[] { "elasticsearch" },
                                "Huseyin Akdogan")).execute().actionGet();

        node.close();
    }

    public static Map<String, Object> putJsonDocument(String title,
            String content, Date postDate, String[] tags, String author) {

        Map<String, Object> jsonDocument = new HashMap<String, Object>();

        jsonDocument.put("title", title);
        jsonDocument.put("conten", content);
        jsonDocument.put("postDate", postDate);
        jsonDocument.put("tags", tags);
        jsonDocument.put("author", author);

        return jsonDocument;
    }

}

我运行ElasticSearch使用命令行:

I run ElasticSearch with command line:

elasticsearch.bat

elasticsearch.bat

和它运行正常:

在这之后,我跑我的Java code,这里是从Eclipse和服务器日志:

After that, I run my Java code and here is a log from Eclipse and server:

我应该配置什么?我见过这样的,每次几个教程实在是类似code,从来没有为我工作。

Should I configure something? I saw few tutorials like this and everytime is really similar code which never works for me.

感谢

推荐答案

好吧,我解决了这个问题。事实上,问题是与ElasticSearch客户端和ES的Java API的版本。

Ok, I solved this problem. In fact, the problem was with the versions of ElasticSearch Client and ES Java API.

升级ES的Java API的版本相同ES客户解决了这个问题。

Upgrade ES Java API to the same version as ES Client solved this problem.

在此处了解详情:

的Java API 1.x的客户端

重要提示:

请注意,我们鼓励您使用相同版本的客户端
  和集群两侧。你可能会碰到一些不兼容的问题时,
  混合主要版本。

Please note that you are encouraged to use the same version on client and cluster sides. You may hit some incompatibilities issues when mixing major versions.

这篇关于ElasticSearch - 无法读取请求数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆