一:启动ElasticSearch
ES后台启动
bi目录下执行如下命令
./elasticsearch -d
二:验证启动是否成功
浏览器输入,返回如下表示启动成功
三:添加es依赖
<dependency><groupId>org.elasticsearch</groupId><artifactId>elasticsearch</artifactId><version>7.8.0</version></dependency><dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId><version>7.8.0</version></dependency>
四:添加索引
public class ElasticsearchTest {public static void main(String[] args) throws IOException {RestHighLevelClient restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));try {//创建索引CreateIndexRequest request = new CreateIndexRequest("hello1");CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);//响应状态boolean acknowledged = createIndexResponse.isAcknowledged();System.out.println("索引操作" + acknowledged);} catch (Exception e) {e.printStackTrace();} finally {restHighLevelClient.close();}}
}
五:用postman查询索引创建情况
可以看到创建hello1索引成功