zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

Elasticsearch 映射4

2023-03-20 14:52:22 时间

为详细的mapping属性可以参考 Mapping ,字段类型可以参考 Field datatypes

PUT mapping API

PUT /{index}/_mapping/{type}
{ body }
  • {index} 可以是以逗号分割的多个索引或匹配符.
  • {type} 是类型名.
  • {body} 中包含了准备应用的映射内容.

更新mapping

总体而言,一般情况下现有字段的mapping是不能被更新的

但以下几种情况例外:

  • 新属性可以被添加到对象的数据类型区域中
  • 新的多字段可以被添加到现存字段中
  • 文档值可以禁用,但不能启用
  • ignore_above 参数可以被更新

字段冲突

在同一个索引中,即便是在不同类型(type)下,相同名字的字段必须拥有相同的mapping,因为在内部的实现中,不同的type如果有相同字段名其实就是在使用相同的字段(基础支持)

所以说索引才是字段类型的名称空间,而类型(type)并不是

在同一索引中,除非使用 update_all_types 参数,否则在不同的type中对一个名字相同的字段进行属性更新时会抛出异常,这个操作事实上会更新这一索引中不同type里所有叫这个名字的字段属性

我的看法是,既然目前ES对一个现成的字段更新不能很好地支持,那么就不要去尝试导入数据后更新这条路,保有的数据越多,就越头疼,直接在事先规划好,设计好,通过充分的考虑根据需求进行指定,就能免去这此问题


命令汇总

  • uname -a
  • cat /etc/issue
  • curl 'localhost:9200/_cat/nodes?h=v'
  • curl -XPUT 'localhost:9200/abc/test/1?pretty' -d '{"name":"joke","age":12}'
  • curl 'localhost:9200/abc/test/1?pretty'
  • curl 'localhost:9200/abc/_mapping?pretty'
  • curl 'localhost:9200/abc?pretty'
  • curl 'localhost:9200/abc/_mapping/test/field/age?pretty'
  • curl 'localhost:9200/abc/_mapping/t*/field/a*?pretty'
  • curl 'localhost:9200/abc/_mapping/test/field/age?pretty&include_defaults=true'
  • curl -XPUT 'localhost:9200/abc/test/2?pretty' -d '{"name":12,"age":23}'
  • curl 'localhost:9200/abc/test/2?pretty'
  • curl 'localhost:9200/abc/_mapping/t*/field/n*?pretty'
  • curl -XPUT 'localhost:9200/abc/test/3?pretty' -d '{"name":"testtype","age":"lili"}'
  • curl 'localhost:9200/abc/test/3?pretty'
  • curl -XPUT 'localhost:9200/abc/_mapping/test?update_all_types&pretty' -d '{"properties" : {"age" : {"type" : "string"}}}'
  • curl 'localhost:9200/abc/_mapping/test/field/age?pretty'
  • curl -XPUT 'localhost:9200/def?pretty' -d '{"mappings": {"test": {"properties": {"userid": {"type": "integer"}}}}}'
  • curl 'localhost:9200/def/_mapping?pretty'
  • curl -XPUT 'localhost:9200/def/_mapping/test?pretty' -d '{"properties": {"city": {"type": "string"}}}'
  • curl 'localhost:9200/def/_mapping?pretty'

原文地址