Elasticsearch:各版本在映射类型上的变化

Elasticsearch5.6.0

  • index.mapping.single_type: 设置该参数为true,将使得对应索引下只能含有一种类型(type),而6.0中强制要求一个索引中只能含有一种类型(type),其优势。

Elasticsearch6.x

  • 在5.x中创建的索引将像在5.x中一样继续在6.x中运行。
  • 在6.x中创建的索引只允许含一种类型,类型名字可以随便指定。首选类型名是_doc,路径:PUT {index}/_doc/{id} 或POST {index}/_doc  ,POST会自动生成随机_id。
  • _type名不再与_id合并组成_uid,_uid称为_id的别名。
  • _default_映射不建议使用。
  • 在6.8中,索引创建、索引模板和映射API支持查询字符串参数(include_type_name),该参数指示请求和响应是否应包含类型名称。默认为true,即默认包含类型名,应该设置为显示值,以便适用7.0,因为7.0中其默认为False。没有显示指明类型名的索引将s使用_doc作为默认类型名。

Elasticsearch7.x

  • 不建议在请求中指定类型,例如,索引一个文档时不再要求文档类型。
  • 新的索引文档的路径为:指定ID -->PUT {index}/_doc/{id} 或随机ID-->POST {index}/_doc,其中_doc表示路径中的端点名称而非文档类型。
  • include_type_name参数在索引创建、索引模版、映射APIS中默认为false,即查询字符串中默认不包含类型名,使用默认的_doc。
  • _default_映射被移除。
  • 检索指定文档时,必须指明:GET {index}/_doc/{id}。

完整例子

  • 创建索引index,设置属性字段"foo"映射(include_type_name=false意味着使用默认_doc类型):
curl -H "Content-Type:application/json" -XPUT 'http://localhost:9200/index?include_type_name=false&pretty' -d '
{
    "mappings":{
		"properties":{ #映射直接在mapping下,没有"_doc"
			"foo":{
				"type":"keyword"
            }
	}
}'
  • 更新索引index的映射,添加新映射字段"bar":
curl -H "Content-Type:application/json" -XPUT 'http://localhost:9200/index/_mappings?include_type_name=false&pretty' -d '
{
    "properties":{
        "bar":{
            "type":"text"
        }
	}
}'
  • 获得索引index的映射信息:
curl -H "Content-Type:application/json" -XGET 'http://localhost:9200/index/_mappings?include_type_name=false&pretty'
  •  向index中索引文档(指明类型_doc)-->文档API:
curl -H "Content-Type:application/json" -XPUT 'http://localhost:9200/index/_doc/1?pretty' -d '
{
    "foo":"baz"
}'
  •  检索文档1(指明 {index}/_doc/{id}):
curl -H "Content-Type:application/json" -XGET 'http://localhost:9200/index/_doc/1?pretty'

 

Elasticsearch8.x

  • 不再支持在请求中指定类型名,创建索引时使用的是默认_doc。
  • include_type_name参数被移除,但检索文档或删除文档时路径:GET {index}/_doc/{id}。

 

 

你可能感兴趣的:(Elasticsearch,elasticsearch,mapping)