Elasticsearch开发过程中踩过的坑

本文总结了在Elasticsearch开发过程中遇到的问题,包括Linux环境下安装启动的难点,以及操作中的常见错误,为读者提供解决方案和经验参考。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值