栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Elasticsearch

Elasticsearch

Linux

关闭防火墙

版本:7.12.1

elasticsearch.yaml
node.name: node-1
network.host: 0.0.0.0
cluster.initial_master_nodes: ["node-1"]
http.cors.enabled: true
http.cors.allow-origin: "*"

Idea pom

    org.springframework.boot
    spring-boot-starter-data-elasticsearch


    org.elasticsearch
    elasticsearch
    7.12.1


    org.elasticsearch.client
    elasticsearch-rest-client
    7.12.1


    org.elasticsearch.client
    elasticsearch-rest-high-level-client
    7.12.1


    com.fasterxml.jackson.core
    jackson-databind
    2.12.3
Esconfig
package com.li.jc.config;

import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;


@Configuration
public class EsConfig {

    public  static final RequestOptions COMMON_OPTIONS;
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
        COMMON_OPTIONS = builder.build();
    }

    @Bean
    public RestHighLevelClient elasticsearchClient() {
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo("192.168.37.128:9200")
                .build();
        return RestClients.create(clientConfiguration).rest();
    }
}
Test
package com.li.jc.test;

import org.elasticsearch.client.RestHighLevelClient;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class EsConnetTest {

    @Autowired
    private RestHighLevelClient restHighLevelClient;
    @Test
    public void testES(){
        System.out.println("11111111111111"+restHighLevelClient);
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/584989.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号