1、ES在Linux安装启动过程中的坑
将安装包上传到Linux下,解压,在普通⽤户下运⾏elasticSearch/bin/elasticsearch ⽂件
注:若是运⾏在root⽤户下,会抛出如下异常:
![请添加图片描述](https://img-blog.csdnimg.cn/fbf41b8fcaef4710b76653ebd5631910.png)
在普通⽤户下正常启动es后,访问 curl -XGET 'http://127.0.0.1:9200
**2、使⽤Java操作客户端操作ES集群**
```java
基于maven的pom 导⼊坐标依赖
<dependencies>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.5.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.61</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
ElasticSearch6.5.3 依赖 lucene7.5.0 版本
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
3、操作
private Client client;
/** 获取client */
@Before
public void getClient() throws Exception {
/*
client = TransportClient.builder().build()
.addTransportAddress(new
InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
*/
//获取client
Settings settings = Settings.builder().put("cluster.name",
"elasticsearch").build();
TransportClient transportClient = new
PreBuiltTransportClient(settings);
transportClient.addTransportAddress(new
TransportAddress(InetAddress.getByName("hadoop00"), 9300));
return transportClient;
}
package com.donggengshou.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Description:Product实体类<br/>
* This program is protected by copyright laws. <br/>
*
* @version : 1.0
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Product {
/**
* 名字
*/
private String name;
/**
* 作者
*/
private String author;
/**
* 版本号
*/
private String last_version;
public Product(String name, String last_version) {
this.name = name;
this.last_version = last_version;
}
}
package com.donggengshou.es;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.donggengshou.entity.Product;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequestBuilder;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action