# ES工具类 **Repository Path**: Sanluobo/es_tool ## Basic Information - **Project Name**: ES工具类 - **Description**: ES工具类 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-07-21 - **Last Updated**: 2021-07-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ES工具类 #### 介绍 ES工具类 #### 软件架构 java #### 安装教程 1. 本地启动ES 配置集群: 1、复制文件2份作为salve节点 2、主节点配置文件 cluster.name: sai_es #簇名----簇即集群,一个簇下都多个节点 node.name: es0 #节点名 node.master: true #是否为主节点 http.port: 9200 #运行端口 #防止head监控的跨域 http.cors.enabled: true http.cors.allow-origin: "*" 3、从节点配置文件 cluster.name: sai_es node.name: es1 node.master: false http.port: 9201 discovery.zen.ping.unicast.hosts: ["127.0.0.1"] 2. 本地启动监控 具体可百度启动 **cnpm install** **grunt server** #### 使用说明 1. 索引类加入@Document注解后使用ElasticsearchRestTemplate.createIndex()方法可以创建索引(必须要有索引类) # 关于分词 创建索引时ES选择进行何种分词,中文使用ik进行分词,ES对其建立索引,例如: 施乐辉医用产品国际贸易(上海)有限公司 :施乐 辉 医用 产品 国际贸易 国际 贸易 上海 有限公司 当搜索词中出现任意一个词或词组即为匹配 http://localhost:8080/select?key=辉医用&indexName=distName&size=200&page=1 这个可以搜索出 施乐辉医用产品国际贸易(上海)有限公司 http://localhost:8080/select?key=用产&indexName=distName&size=200&page=1 无法搜索出 //@Document可被识别为索引类 ``` @Document(indexName = "snn_dist") public class Dist { @Id private String id; @Field(index = true,type = FieldType.Text , analyzer = "ik_max_word") /* "dist_code":{ "type":"text", "analyzer": "ik_max_word" }, */ private String distCode; @Field(index = true,type = FieldType.Text , analyzer = "ik_max_word") private String sysOrgCode; @Field(index = true,type = FieldType.Text , analyzer = "ik_max_word") private String distName; @Field(index = true,type = FieldType.Text , analyzer = "ik_max_word") private String creditCode; @Field(index = true,type = FieldType.Text) private String deleteFlag; } ```