mapping创建 添加记录到es
2017-06-05 17:10
381 查看
/** * 索引的mapping * <p> * 预定义一个索引的mapping,使用mapping的好处是可以个性的设置某个字段等的属性 * Es_Setting.INDEX_DEMO_01类似于数据库 mapping 类似于预设某个表的字段类型 * <p> * Mapping,就是对索引库中索引的字段名及其数据类型进行定义,类似于关系数据库中表建立时要定义字段名及其数据类型那样, 不过es的 * mapping比数据库灵活很多,它可以动态添加字段。 一般不需要要指定mapping都可以,因为es会自动根据数据格式定义它的类型, * 如果你需要对某 些字段添加特殊属性(如:定义使用其它分词器、是否分词、是否存储等),就必须手动添加mapping。 * 有两种添加mapping的方法,一种是定义在配 置文件中,一种是运行时手动提交mapping,两种选一种就行了。 * * 创建mapping(feid("indexAnalyzer","ik")该字段分词IK索引 * ;feid("searchAnalyzer","ik")该字段分词ik查询;具体分词插件请看IK分词插件说明) * * @param indices * 索引名称; * @param mappingType * 索引类型 * @throws Exception * Exception */ protected static void buildMappingdatafile_commcust_info(String indices, String mappingType) throws Exception { EsUtils.client.admin().indices().prepareCreate(indices).execute().actionGet(); //2.create a mapping XContentBuilder mapping = XContentFactory.jsonBuilder().startObject() .startObject(mappingType) .startObject("_all") .field("analyzer", "whitespace") .field("search_analyzer", "whitespace") .field("term_vector","no") .field("store","false") .endObject() .startObject("properties") .startObject("id").field("type","text").field("index","false").field("include_in_all","false").endObject()//主键,不做索引 .startObject("emptycol").field("type","text").field("index","false").field("include_in_all","false").endObject()//未命名列,不做索引 .startObject("comm_no").field("type","keyword").endObject()//通讯号码,不做分词 .startObject("cust_name").field("type","keyword").endObject()//客户名称,不做分词 .startObject("cust_addr").field("type","text").field("analyzer","ik_max_word").field("search_analyzer","ik_max_word").endObject()//客户地址 .startObject("cust_id_type").field("type","keyword").endObject()//证件类型, .startObject("cust_id_no").field("type","keyword").endObject()//证件号码 .startObject("create_time").field("type","date").endObject()//创建时间,基本列 .startObject("data_src").field("type","text").field("index","false").field("include_in_all","false").endObject()//数据来源,基本列 .startObject("creator").field("type","text").field("index","false").field("include_in_all","false").endObject()//创建人,基本列 .endObject() // end 'properties object' .endObject() // end 'mappingType object' .endObject(); // end ' object' PutMappingRequest mappingRequest = Requests.putMappingRequest(indices).type(mappingType).source(mapping); EsUtils.client.admin().indices().putMapping(mappingRequest).actionGet(); }
相关文章推荐
- ES 对各字段创建分词 和mapping创建 个人操作记录
- DataTable创建、数据的添加及数据记录的排序,检索,合并,分页,统计(整理)
- Oracle中创建表,创建序列,创建自增字段,添加注释, 添加记录,添加触发器,提交
- 为Oraclespatial表添加记录和创建空间索引
- ES Java API - 查询索引的mapping、status状态、索引创建时间
- 为Oraclespatial表添加记录和创建空间索引
- 用SELECT 创建记录和表 添加多个记录
- mysql 创建存储过程 循环添加记录
- es 为某个type创建mapping
- Elasticsearch创建索引,删除索引,添加mapping
- VC 操作ACCESS的创建数据库,表,添加修改删除记录等
- SQL语句――创建表,添加记录
- MySQL中创建、删除表和库,添加、删除记录
- 创建Cookie,简单模拟登录,记录登录名,购物车记录先前添加内容,session控制登录
- 程序创建更改主记录并添加WBS元素BOM
- Oracle中创建表,创建序列,创建自增字段,添加注释, 添加记录,添加触发器
- mysql::创建多个表空间添加记录数据会添加到哪个表空间中?
- access用sql创建表,文本类型字段添加记录时文本后有空格,解决办法
- Es创建索引、设置和修改Mapping
- ElasticSearch创建索引(index)和添加映射(mapping)