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. Linux安装redis PHP安装Redis扩展 and基本命令

    一.安装redis 用超级管理员身份运行: $ mkdir /usr/local/redis #redis安装目录 $ cd /usr/local/src #安装包下载目录 $ wget http:/ ...

  2. Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate failed: Exception getting JDBC Driver: com.mysql.jdbc.Driver (mybatis逆向工程)

    springboot整合mybatis时出现的问题 解决方法:在pom.xml中plugin中加入单独依赖Mysql驱动包,问题便可解决 <plugin> <groupId>o ...

  3. SpringBoot配置全局自定义异常

    不同于传统集中时Springmvc 全局异常,具体查看前面的章节https://www.cnblogs.com/zwdx/p/8963311.html 对于springboot框架来讲,这里我就介绍一 ...

  4. 配置p6spyLog输出sql完整日志

      第一步:   配置maven <dependency> <groupid>p6spy</groupid> <artifactid>p6spy< ...

  5. 微信小程序 - 生命周期 - 参数传递

    ​ 现在WEB开发门槛越来越高,不想java 会了就可以有工作,前端不行 ,不仅JavaScript要求不低,基础的HTML+CSS还要扎实,jquery也是必须要会,现在的前端框架 Vue Ng R ...

  6. Volatile的详解

    volatile关键字修饰的共享变量主要有两个特点:1.保证了不同线程访问的内存可见性    2.禁止重排序 在说内存可见性和有序性之前,我们有必要看一下Java的内存模型(注意和JVM内存模型的区分 ...

  7. BigData--hadoop集群搭建之zookeer安装

    Zookeeper安装 cd /opt/ tar -zxvf zookeeper-3.4.10.tar.gzmv zookeeper-3.4.10  /opt/zookeeper修改配置文件cd /o ...

  8. hive 从Excel中导入数据

    拿到Excel表后将数据保留,其他的乱七八糟都删掉,然后另存为txt格式的文本,用nodepad++将文本转换为UTF-8编码,此处命名为cityprovince.txt 将cityprovince. ...

  9. LeetCode 二叉树的层次遍历 C++

    给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 例如:给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回其层 ...

  10. BZOJ3265: 志愿者招募加强版(线性规划)

    Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 809  Solved: 417[Submit][Status][Discuss] Descriptio ...