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 ...
随机推荐
- python中pip问题
1.在cmd中运行pip命令显示‘pip命令显示不是内部或外部命令,也不是可运行的程序或批处理文件’的问题 先看python的安装目录下Script文件夹中pip3.exe有没有缺失 如果没有在cmd ...
- 30分钟编写一个抓取 Unsplash 图片的 Python爬虫
我一直想用 Python and Selenium 创建一个网页爬虫,但从来没有实现它. 几天前, 我决定尝试一下,这听起来可能是挺复杂的, 然而编写代码从 Unsplash 抓取一些美丽的图片 ...
- google插件跨域含用户请求WebApi解决的方案
问题描述: google插件跨域请求WebApi相关解决方案 1.ajax解决含登录用户信息 $.ajax({ url: url, type: "POST", timeout: 6 ...
- Tarjan-SCC-NOIP2015message
This article is made by Jason-Cow.Welcome to reprint.But please post the writer's address. http://ww ...
- php截取富文本框中的固定长度的字符
ai,哎怎么赶脚自己写东西越来越小儿科了呢,现在连这个问题都找了好半天 因为后台是的内容是富文本编辑器编辑的,前台我傻逼的直接截取了字符串,然后样式啥的都乱了,找了半天是因为富文本的问题 其实解决办法 ...
- Mysql实现级联操作(级联更新、级联删除)(转)
一.首先创建两张表stu,sc create table stu( sid int UNSIGNED primary key auto_increment, name varchar(20) not ...
- Eclipse代码规范
配置代码自动格式化 1.导入规范文件 codeStyle.xml <?xml version="1.0" encoding="UTF-8" standa ...
- eclipse中怎么导入git库下载下来的web项目
总的看来是有两种方式: 方式一:可以对已经从版本库下载到本地的项目操作(Maven导入) 你可以通过公司提供的内部的版本库的网址登录版本库,之后在里面下载自己想要的那个版本的代码包,见下图 点击右侧的 ...
- C:产生随机数
函数说明 #include <time.h> time_t time(time_t *t); 功能:获取当前系统时间 参数:常设置为NULL 返回值:当前系统时间, time_t 相当于l ...
- 自己实现java中Iterator(迭代器功能)
今天躺在床上忽然想到一个问题,迭代器的代码是如何实现的?于是乎不由自主的爬起来敲两行代码. List<String> list=new ArrayList<>(2); list ...