Elasticsearch索引mapping的写入、查看与修改

https://blog.csdn.net/napoay/article/details/52012249

首先创建一个索引:

curl -XPOST "http://127.0.0.1:9200/productindex"
{"acknowledged":true}
1
2
现在只创建了一个索引,并没有设置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机制的。
这里有一篇关于修改mapping字段的博客,叙述的比较清楚:Elasticsearch 的坑爹事——记录一次mapping field修改过程,可以参考.

ES mapping的写入与查看的更多相关文章

  1. Elasticsearch索引mapping的写入、查看与修改(转)

    mapping的写入与查看 首先创建一个索引: curl -XPOST "http://127.0.0.1:9200/productindex" {"acknowledg ...

  2. (转)Elasticsearch索引mapping的写入、查看与修改

    mapping的写入与查看 首先创建一个索引: curl -XPOST "http://127.0.0.1:9200/productindex" {"acknowledg ...

  3. ES mapping可以修改include_in_all,也可以修改index_options,norm,但是无法修改_all属性!

    ES mapping可以修改include_in_all,也可以修改index_options,norm,但是无法修改_all属性! curl -XPOST "http://localhos ...

  4. ES mapping映射及优化

    mapping映射 主要类型: 同一index下,不同type中如果有相同filed:es进行mapping映射的时候,按照先写进去的指定类型:比如同一index,包含的type中都有key1字段,如 ...

  5. ES mapping field修改过程

    Elasticsearch 的坑爹事--记录一次mapping field修改过程 http://www.cnblogs.com/Creator/p/3722408.html Elasticsearc ...

  6. python 创建es mapping

    import requests def get_(): url = "http://127.0.0.1:9200/indextest/_mapping?pretty" ss = r ...

  7. ZT:在mybatis的Mapping文件写入表名 出现异常ORA-00903: 表名无效 的解决

    简而言之,把#{tablename}换成${tablename}就能解决问题. 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:htt ...

  8. ES 创建mapping

    mapping的写入与查看首先创建一个索引: curl -XPUT "http://erp2.es.kd1.pagoda.com.cn:80/erp_stock_index"{&q ...

  9. 【Elasticsearch】Elasticsearch索引的创建、查看及修改

    转: 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/liuxiao723846/art ...

随机推荐

  1. 一张图理解UINavigationBar,UINavigationItem,UIBarButtonItem,UITabBar,UITabBarItem,UITabBarButton

  2. centos搭建SVN服务

    Linux VM_47_236_centos 3.10.0-514.21.1.el7.x86_64 需求:android.ios.service三个版本库 安装: yum -y install sub ...

  3. python学习——函数

     一.在python的世界里什么是函数: 答:函数通常是用来实现某一个功能二被封装成的一个对象,是用来实现代码复用的常用方式 现在有一个需求,假如你在不知道len()方法的情况下,要你计算字符串‘he ...

  4. windows环境下安装scrapy框架报错问题--最快捷有效的解决方案

    windows在执行如下命令,安装scrapy的过程中会报错: pip install scrapy 报错分析: windows环境下,会出现如下错误: 1.提示的错误是编译环境的问题,字面意思看需要 ...

  5. 来自一个大三开学三周的huster的迷茫与失措

    大三开学考研保研的话题开始多了起来.自从前天去听了一回谢长生教授的实验室宣讲会,回来直到现在都好像心头上压了些东西,喘不过气来.本来我就少与外界接触,加之我自己一个人主动学习的积极性也很是缺乏,所以当 ...

  6. C语言实例解析精粹学习笔记——31

    实例31: 判断字符串是否是回文 思路解析: 引入两个指针变量(head和tail),开始时,两指针分别指向字符串的首末字符,当两指针所指字符相等时,两指针分别向后和向前移动一个字符位置,并继续比较, ...

  7. Educational Codeforces Round 47 (Rated for Div. 2) :D. Relatively Prime Graph

    题目链接:http://codeforces.com/contest/1009/problem/D 解题心得: 题意就是给你n个点编号1-n,要你建立m条无向边在两个互质的点之间,最后所有点形成一个连 ...

  8. dijkstra算法学习

    dijkstra算法学习 一.最短路径 单源最短路径:计算源点到其他各顶点的最短路径的长度 全局最短路径:图中任意两点的最短路径 Dijkstra.Bellman-Ford.SPFA求单源最短路径 F ...

  9. linux c 出错集

    2018.7.8 1.声明结构体时,结构体内部不能赋值.比如 struct student{ char id=0; char score=0; }; 这样大错特错! 2.字符数组 char a[10] ...

  10. xssbypass小记

    简单整理下bypass的一些点 标签外 如果是标签之外 又有htmlspecialchars函数的点 就别想了 在标签外同时能xss但是有长度限制 如果是储存型可以利用多个点 然后构造<scri ...