ES 创建mapping
mapping的写入与查看
首先创建一个索引:
curl -XPUT "http://erp2.es.kd1.pagoda.com.cn:80/erp_stock_index"
{"acknowledged":true}
现在只创建了一个索引,并没有设置mapping,查看一下索引mapping的内容:
curl -XGET "http://127.0.0.1:9200/productindex/_mapping?pretty"
{
"productindex" : {
"mappings" : { }
}
}
可以看到mapping为空,我们只创建了一个索引,并没有进行mapping配置,mapping自然为空。
下面给productindex这个索引加一个type,type name为product,并设置mapping:
curl -XPOST "http://127.0.0.1:9200/productindex/product/_mapping?pretty" -d '
{
"product": {
"properties": {
"title": {
"type": "string",
"store": "yes"
},
"description": {
"type": "string",
"index": "not_analyzed"
},
"price": {
"type": "double"
},
"onSale": {
"type": "boolean"
},
"type": {
"type": "integer"
},
"createDate": {
"type": "date"
}
}
}
}
'
{
"acknowledged" : true
}
上面的操作中,我们给productindex加了一个type,并写入了product的mapping信息,再次查看:
curl -XGET "http://127.0.0.1:9200/productindex/_mapping?pretty"
{
"productindex" : {
"mappings" : {
"product" : {
"properties" : {
"createDate" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
},
"description" : {
"type" : "string",
"index" : "not_analyzed"
},
"onSale" : {
"type" : "boolean"
},
"price" : {
"type" : "double"
},
"title" : {
"type" : "string",
"store" : true
},
"type" : {
"type" : "integer"
}
}
}
}
}
}
修改mapping
如果想给product新增一个字段,那么需要修改mapping,尝试一下:
curl -XPOST "http://127.0.0.1:9200/productindex/product/_mapping?pretty" -d '{
"product": {
"properties": {
"amount":{
"type":"integer"
}
}
}
}'
{
"acknowledged" : true
}
新增成功。
如果要修改一个字段的类型呢,比如onSale字段的类型为boolean,现在想要修改为string类型,尝试一下:
curl -XPOST "http://127.0.0.1:9200/productindex/product/_mapping?pretty" -d '{
"product": {
"properties": {
"onSale":{
"type":"string"
}
}
}
}'
返回错误:
{
"error" : {
"root_cause" : [ {
"type" : "illegal_argument_exception",
"reason" : "mapper [onSale] of different type, current_type [boolean], merged_type [string]"
} ],
"type" : "illegal_argument_exception",
"reason" : "mapper [onSale] of different type, current_type [boolean], merged_type [string]"
},
"status" : 400
}
为什么不能修改一个字段的type?原因是一个字段的类型修改以后,那么该字段的所有数据都需要重新索引。Elasticsearch底层使用的是lucene库,字段类型修改以后索引和搜索要涉及分词方式等操作,不允许修改类型在我看来是符合lucene机制的。
ES 创建mapping的更多相关文章
- ES创建mapping时字段别名
ES默认是动态创建索引和索引类型的mapping的,但是在学习的时候还能这样用,在生产中一定是手动制定mapping!在生产中经常会遇到这样的需求,想用某个字段进行统计,又想对该字段进行模糊查询,解决 ...
- 关闭ES动态创建mapping
使用ES的默认配置会使我们在索引不存在于mapping中的字段时,会自动创建. 这无疑会给我们带来困扰. 在我们不想要某个字段被搜索的时候,我们可以在开始关闭动态创建mapping. 执行如下操作: ...
- Es创建索引、设置和修改Mapping
Http接口操作示例如下: 1.创建索引: 2.删除索引: 3.创建mapping: 4.查看mapping:
- slid.es – 创建在线幻灯片和演示文稿的最佳途径
slid.es 提供了一种创建在线幻灯片和演示文稿的简单方法,让你通过几个简单的步骤制作效果精美的在线演示文稿.基于 HTML5 和 CSS3 实现,在现代浏览器中效果最佳. 您可能感兴趣的相关文章 ...
- es创建索引的格式,并初始化数据
es创建索引的格式,并初始化数据 学习了:https://www.imooc.com/video/15759 1, 创建格式 POST 127.0.0.1:9200/book/novel/_mappi ...
- elasticsearch: 创建mapping
elasticsearch版本: 6.5.4 创建mapping PUT http://192.168.2.136:9200/index_text/_mapping/text/ { "dyn ...
- es的mapping设置
自定义mapping的api PUT test_index { "mappings": { #mappings关键字 "doc": { #type " ...
- es创建普通索引以及各种查询
创建索引 创建普通索引: PUT /my_index { "settings": { "index": { "number_of_shards&quo ...
- [Elasticsearch] ES 的Mapping 设计在实际场景中应用
背景 项目中有个需求是需要几个字段作为标签,统计各个标签的文档数量,同时支持分词后的全文检索功能. 原有的mapping设计: curl -XPUT http://ip:9200/meta_es_me ...
随机推荐
- ASP.NET Core 使用过滤器移除重复代码
USING ACTIONFILTERS TO REMOVE DUPLICATED CODE ASP.NET Core 的过滤器可以让我们在请求管道的特定状态之前或之后运行一些代码.因此如果我们的 ac ...
- 计算机网络 - TCP_NODELAY 和 TCP_CORK, TCP_NOPUSH
参考 https://www.cnblogs.com/biyeymyhjob/p/4670502.html https://stackoverflow.com/questions/3761276/wh ...
- Redis04——Redis五大数据类型 key
key keys * 查看当前库的所有键 exists <key> 判断某个键是否存在 type <key> 查看键的类型 del<key> 删除 ...
- 移动端适配rem为单位的rem.js及个别设备设置了大字体模式,导致页面变形的处理方式
这段时间内,涉及到的都是移动端开发,说到移动端开发,我们就会思考到,目前分辨率的问题,如果用px为单位的话,在不同移动设备和不同分辨率下,页面的效果可能会有所不同,甚至导致页面变形.所以在次我们就用到 ...
- FileOutputStream,BufferedOutputStream,FileWriter 效率比较
测试代码: /** * 写文件 * FileOutputStream, BufferedOutputStream, FileWriter * 三个流 效率比较 */ @Test public void ...
- Java - Test - TestNG: Idea 添加 TestNG 依赖
1. 概述 Idea 开发的 maven 添加 testng 依赖 2. 背景 最近复习 TestNG 尝试搭建环境 发现教材和网上很多的教程, 都是 eclipse 的 我用的是 idea 这个貌似 ...
- (办公)记事本_linux网络命令
参考谷粒学院的linux视频教程:http://www.gulixueyuan.com/course/300/task/7091/show 阿里云ECS云服务器更换公网IP的方法:https://yq ...
- es6二进制数组--基础
一.概念二进制数组由 ArrayBuffer对象 TypeArray 视图和DataView视图 三部分组成是javascript操作二进制数据的一个接口. 早在2011年2月就已经发布,但是由于ES ...
- ajax中 踩过的坑
直接上图: 以前一直对 dataType 这个参数 模棱两可,只知道一般写的是 json 正解:这个dateType 指的是 ajax 返回数据的格式.比如:你想返回一个“success& ...
- EF 查询表达式 join
数据源: 1.无into,相当于 inner join var query = from p in context.P join s in context.S on p.PID equals s.PI ...