elasticsearch java动态设置mapping并指定分词器
//创建索引
client.admin().indices().prepareCreate("twitter").execute().actionGet();
//配置mapping
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject()
.startObject("tweet")
.startObject("properties")
.startObject("user").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject()
.startObject("message").field("type", "string").field("store", "yes").field("index", "analyzed").endObject()
.startObject("postDate").field("type", "date").endObject()
// .startObject("content").field("type","string").field("store","yes").field("analyzer","ik").field("search_analyzer","ik_smart").endObject()
.startObject("content").field("type", "string").field("store", "yes").field("analyzer", "ik").endObject()
.endObject()
.endObject()
.endObject();
PutMappingRequest mappingRequest = Requests.putMappingRequest("twitter").type("tweet").source(mapping);
client.admin().indices().putMapping(mappingRequest).actionGet(); // 批量插入数据
BulkRequestBuilder bulkRequest = client.prepareBulk();
IndexRequest request = client.prepareIndex("twitter", "tweet", "1").setSource(json).request();
IndexRequest request2 = client.prepareIndex("twitter", "tweet", "2").setSource(json2).request();
bulkRequest.add(request);
bulkRequest.add(request2);
bulkRequest.execute().actionGet();
client.close();
index的值只有三种(no,not_analyzed,analyzed)
https://www.elastic.co/guide/en/elasticsearch/reference/2.4/mapping-index.html
no:不添加到索引
not_analyzed:添加到索引不分词
analyzed : 添加到索引并分词
elasticsearch java动态设置mapping并指定分词器的更多相关文章
- Elasticsearch教程(三),IK分词器安装 (极速版)
如果只想快速安装IK,本教程管用.下面看经过. 简介: 下面讲有我已经打包并且编辑过的zip包,你可以在下面下载即可. 当前讲解的IK分词器 包的 version 为1.8. 一.下载zip包. 下面 ...
- ElasticSearch(二十六)修改分词器及定制自己的分词器
1.默认的分词器 standard 分词器 standard tokenizer:以单词边界进行切分standard token filter:什么都不做lowercase token filter: ...
- (2)ElasticSearch在linux环境中集成IK分词器
1.简介 ElasticSearch默认自带的分词器,是标准分词器,对英文分词比较友好,但是对中文,只能把汉字一个个拆分.而elasticsearch-analysis-ik分词器能针对中文词项颗粒度 ...
- docker 部署 elasticsearch + elasticsearch-head + elasticsearch-head跨域问题 + IK分词器
0. docker pull 拉取elasticsearch + elasticsearch-head 镜像 1. 启动elasticsearch Docker镜像 docker run -di ...
- Linux使用Docker启动Elasticsearch并配合Kibana使用,安装ik分词器
注意事项 这里我的Linux虚拟机的IP地址是192.168.1.3 Docker运行Elasticsearch容器之后不会立即有反应,要等一会,等待容器内部启动Elasticsearch,才可以访问 ...
- elasticsearch Mapping使用自定义分词器
创建索引及配置分析器 PUT /my_index { "settings": { "analysis": { "char_filter": ...
- Elasticsearch教程(二),IK分词器安装
elasticsearch-analysis-ik 是一款中文的分词插件,支持自定义词库,也有默认的词库. 开始安装. 1.下载 下载地址为:https://github.com/medcl/ela ...
- ElasticSearch(六):安装中文分词器插件smartcn
首先进入elasticsearch的bin目录 然后执行 # sh elasticsearch-plugin install analysis-smartcn 安装完成后,需要重启elasticse ...
- elasticsearch最全详细使用教程:入门、索引管理、映射详解、索引别名、分词器、文档管理、路由、搜索详解
一.快速入门1. 查看集群的健康状况http://localhost:9200/_cat http://localhost:9200/_cat/health?v 说明:v是用来要求在结果中返回表头 状 ...
随机推荐
- iOS常用宏定义大全
宏定义与常量的区别 宏:只是在预处理器里进行文本替换,不做任何类型检查,宏能定义代码,const不能,多个宏编译时间相对较长,影响开发效率,调试过慢,const只会编译一次,缩短编译时间. 所以在使用 ...
- CRM和C4C里的组织架构 - Organizational Structure
CRM(WebClient UI) CRM(SAP GUI,事务码PPOMA_CRM) C4C 以列表方式显示: 以图形方式显示: UI模型: /SAP_BYD_APPLICATION_UI/mom/ ...
- linux之xargs
xargs从标准输入(stdin)中读取数据进行处理 数据以空格进行分隔 可以根据参数进行一次或多次处理,默认的处理命令是/bin/echo 空行不进行处理,会被忽略 遇到命令状态为255时,xarg ...
- 用mybatis将SQL查询语句”select * from user”的封装为配置文件
用mybatis将SQL查询语句”select * from user”的封装为配置文件 定义一个xml映射文件,文件名见名知意.如user-mapper.xml,文件内容如下: <?xml v ...
- mysql常用的存储引擎,MyISAM和InnoDB的对比
Mysql有多种存储引擎,最常用的有MyISAM和InnoDB这两种,每一种类型的存储引擎都有自已的特点,可以结合项目中数据的使用场景来进行了哪种存储引擎合适. 1:查看mysql数据库支持的存储引擎 ...
- centos搭建集群
centos 搭建集群步骤 1.使用yum安装所需要的工具 yum -y install wget vim tcl gcc make 2.下载redis并解压 cd /usr/local wget h ...
- 【SpringMVC】入门
一.概述 1.1 SpringMVC是什么 1.2 MVC在b/s系统的应用 1.3 SpringMVC 原理 二.入门程序 2.1 需求 2.2 引入依赖 2.3 前端控制器 2.4 springm ...
- Metasploit Penetration (第一夜加班)
1.最近白天瞒着上班,晚自习看英语,还要瞒着写论文(现在是看,之前的部分章节被老师否定了,现在开始要从新进行整理)所以只有这晚上来开始看我的渗透测试了,发现渗透的很多知识,只要你平时不用很快就会生疏, ...
- CA、证书及openssl用法
CA和证书 摘要:涉及到网络安全这一块,想必大家都听过CA吧.像百度.淘宝.京东等这些知名网站,每年都要花费一笔money来买CA证书.但其实简单的企业内的CA认证,我们自己就可以实现,今天我就讲解一 ...
- 【问题】Difference between ">/dev/null 2>&1" and "2>&1 >/dev/null"
https://www.unix.com/shell-programming-and-scripting/125947-difference-between-dev-null-2-1-2-1-dev- ...