elasticsearch5.0中head连不上es,集群健康值: 未连接

(1) elasticsearch-5x下的 config/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
(2)elasticsearch-head下Gruntfile.js
connect: {
        server: {
            options: {
                hostname: '0.0.0.0',
                port: 9100,
                base: '.',
                keepalive: true
            }
        }
    }   
(3)浏览器问题:chrom不能连,换ie试试
  • 8
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 33
    评论
要使用Elasticsearch的Java API连接Elasticsearch集群,需要添加以下三个依赖:org.elasticsearch.client.elasticsearch-rest-high-level-client、org.elasticsearch.client:elasticsearch-rest-client、org.elasticsearch:elasticsearch。这些依赖可以通过Maven或Gradle添加到项目。接下来,可以使用Elasticsearch的Java API编写代码来连接Elasticsearch集群。具体步骤如下: 1. 创建RestHighLevelClient对象,该对象是与Elasticsearch集群进行通信的主要入口点。 2. 创建IndexRequest对象,该对象表示要索引的文档。 3. 使用IndexRequest对象设置索引名称、文档类型和文档ID等信息。 4. 使用IndexRequest对象设置要索引的文档内容。 5. 使用RestHighLevelClient对象执行IndexRequest对象,将文档索引到Elasticsearch集群。 下面是一个示例代码,用于将文档索引到Elasticsearch集群: ```java import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.rest.RestStatus; import java.io.IOException; public class ElasticsearchExample { private RestHighLevelClient client; public ElasticsearchExample(RestHighLevelClient client) { this.client = client; } public void indexDocument(String index, String type, String id, String json) throws IOException { IndexRequest request = new IndexRequest(index, type, id); request.source(json, XContentType.JSON); IndexResponse response = client.index(request, RequestOptions.DEFAULT); if (response.status() == RestStatus.CREATED) { System.out.println("Document indexed successfully"); } else { System.out.println("Failed to index document"); } } public static void main(String[] args) throws IOException { RestHighLevelClient client = new RestHighLevelClient(/* Elasticsearch连接配置 */); ElasticsearchExample example = new ElasticsearchExample(client); example.indexDocument("my_index", "my_type", "1", "{\"name\":\"John Doe\",\"age\":25}"); client.close(); } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 33
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值