Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试访问弹性搜索时,使用java获取空响应_Java_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Kibana - Fatal编程技术网 elasticsearch,kibana,Java,elasticsearch,Kibana" /> elasticsearch,kibana,Java,elasticsearch,Kibana" />

尝试访问弹性搜索时,使用java获取空响应

尝试访问弹性搜索时,使用java获取空响应,java,elasticsearch,kibana,Java,elasticsearch,Kibana,遵循Elastic Search的文档,我们能够为其API设置Java环境。 但当尝试从名为twitter的索引访问时,在名为tweet的类型下,id值为1,响应为null,控制台中没有错误 上面的代码 Settings settings = Settings.builder() .put("cluster.name", "elasticsearch").build(); TransportClient client = new PreBuilt

遵循Elastic Search的文档,我们能够为其API设置Java环境。 但当尝试从名为twitter的索引访问时,在名为tweet的类型下,id值为1,响应为null,控制台中没有错误

上面的代码

Settings settings = Settings.builder()
                .put("cluster.name", "elasticsearch").build();

        TransportClient client = new PreBuiltTransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

        GetResponse response = client.prepareGet("twitter", "tweet", "2").get();
        System.out.println(response.getFields());

        client.close();
Kibana控制台数据,用于相同的

{
        "_index": "twitter",
        "_type": "tweet",
        "_id": "2",
        "_score": 1,
        "_source": {
          "user": "Rahul",
          "post_date": "2009-11-15T14:12:12",
          "message": "trying out Elasticsearch"
        }
      },
      {
        "_index": "twitter",
        "_type": "tweet",
        "_id": "1",
        "_score": 1,
        "_source": {
          "user": "kimchy",
          "post_date": "2009-11-15T14:12:12",
          "message": "trying out Elasticsearch"
        }
      }

请尝试一下像这样的东西,希望能有所帮助

RestClient restClient = RestClient.builder(
                new HttpHost("localhost", 9200, "http")).build();

        Response response = restClient.performRequest("GET", "/twitter/_search",
               Collections.singletonMap("pretty", "true"));


/*
        JsonObject user = new JsonObject();
        user.addProperty("user","Yash");
        user.addProperty("post_date","2009-11-15T14:12:12");
        user.addProperty("message","Checking json");

        HttpEntity entity = new NStringEntity(user.toString());

        Response indexResponse = restClient.performRequest(
                "PUT",
                "/twitter/tweet/3",
                Collections.<String, String>emptyMap(),
                entity);
*/





        System.out.println(EntityUtils.toString(response.getEntity()));

        restClient.close();

确保您使用的是HTTP,而不是HTTPs-如果您发出一个简单的纯文本HTTP请求,服务器可能会挂断您的连接?

您可以添加一个链接来准备Get函数吗?curl-XGET“localhost:9200/twitter/tweet/0?pretty”@Lax只有在我尝试通过java访问它失败时,kibana控制台中的数据才能正常工作,甚至还检查了集群名称