Open Pyohwan opened 4 years ago
index.mapping.single_type
를 설정안해도 된다.twitter
인덱스를 tweets
인덱스와 users
인덱스로 나눈다
PUT users
{
"settings": {
"index.mapping.single_type": true
},
"mappings": {
"_doc": {
"properties": {
"name": {
"type": "text"
},
"user_name": {
"type": "keyword"
},
"email": {
"type": "keyword"
}
}
}
}
}
PUT tweets { "settings": { "index.mapping.single_type": true }, "mappings": { "_doc": { "properties": { "content": { "type": "text" }, "user_name": { "type": "keyword" }, "tweeted_at": { "type": "date" } } } } }
POST _reindex { "source": { "index": "twitter", "type": "user" }, "dest": { "index": "users", "type": "_doc" } }
POST _reindex { "source": { "index": "twitter", "type": "tweet" }, "dest": { "index": "tweets", "type": "_doc" } }
### Custom type field
* 다음 예는 커스텀 `type` 필드를 추가하고 original `_type` 의 값을 입력한다.
* 또한 충돌하는 IDs 를 가진 다른 타입의 문서가 있다면, `_id` 타입에 추가한다.
```json
PUT new_twitter
{
"mappings": {
"_doc": {
"properties": {
"type": {
"type": "keyword"
},
"name": {
"type": "text"
},
"user_name": {
"type": "keyword"
},
"email": {
"type": "keyword"
},
"content": {
"type": "text"
},
"tweeted_at": {
"type": "date"
}
}
}
}
}
POST _reindex
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter"
},
"script": {
"source": """
ctx._source.type = ctx._type;
ctx._id = ctx._type + '-' + ctx._id;
ctx._type = '_doc';
"""
}
}
대상 인덱스에 커스텀 type 이 포함되어 있어도, typeless API 는 동작한다. 예를들어, 인덱스가
my_type
이라는 커스텀 타입 이름을 가졌을시, typelessindex
호출로 인덱스를 추가하고, typelessget
호출로 문서를 읽을 수 있다.Index APIs
include_type_name
URL 파라미터를 지원한다.
true
이며, 매핑에서 type 이름을 사용하는 pre-7.0 동작과 일치한다.false
이며, 8.0 에서는 제거될것이다.include_type_name
를 설정하면 deprecation warning 이 발생한다.false
로 하고 Elasticsearch 와 상호작용 하는 몇가지 예를 보여준다.
PUT index?include_type_name=false
{
"mappings": {
"properties": {
"foo": {
"type": "keyword"
}
}
}
}
mappings
키 바로 아래 포함됩니다.
PUT index/_mappings?include_type_name=false
{
"properties": {
"bar": {
"type": "text"
}
}
}
매핑은 type 이름 없이, mappings
키 바로 아래 포함됩니다.
GET index/_mappings?include_type_name=false
"index": {
"mappings": {
"properties": {
"foo": {
"type": "keyword"
},
"bar": {
"type": "text"
}
}
}
}
}
mappings
키 바로 아래 포함됩니다.{index}/_doc
path 와 명시적인 ids 를 가진 {index}/_doc/{id}
로 호출 되어야 한다.PUT index/_doc/1
{
"foo": "baz"
}
{
"_index": "index",
"_id": "1",
"_type": "_doc",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
유사하게 get
과 delete
APIs 는 {index}/_doc/{id}
path 를 사용한다.
GET index/_doc/1
7.0 에서
_doc
는 document 타입이 아니라 endpoint 를 나타낸다._doc
컴포넌트는 document 의index
,get
,delete
API 의 영구적인 부분이며, 8.0 에서 제거되지 않는다.
_update
와 같은 endpoint 를 포함하는 API paths 는, 7.0 에서는 index 이름을 즉시 따른다.
POST index/_update/1
{
"doc" : {
"foo" : "qux"
}
}
GET /index/_source/1
* 요청 본문에 type 이 더이상 나타나지 않아야 한다. 다음의 bulk indexing 예제에서는, URL 과 개별 bulk 명령어에서 type 이 생략된다.
```json
POST _bulk
{ "index" : { "_index" : "index", "_id" : "3" } }
{ "foo" : "baz" }
{ "index" : { "_index" : "index", "_id" : "4" } }
{ "foo" : "qux" }
_search
, _msearch
, _explain
와 같은 search API 를 호출할때, type 이 URL 에 포함되어서는 안된다. 또한, _type
필드는 queries, aggregations, scripts 에도 사용되서는 안된다._type
key 를 계속 반환하는데, 이는 응답 파싱 실패를 피해기 위함이다.
_doc
type 를 반환한다.
get
호출은 mapping 에 커스텀 타입인 my_type
같은게 있더라도, _doc
type 을 항상 반환한다.
PUT index/my_type/1
{
"foo": "baz"
}
GET index/_doc/1
{ "_index" : "index", "_type" : "_doc", "_id" : "1", "_version" : 1, "_seq_no" : 0, "_primary_term" : 1, "found": true, "_source" : { "foo" : "baz" } }
### Index templates
* `include_type_name` 을 `false` 로 설정하여, typeless index 템플릿을 re-adding 으로 만드는것을 추천한다.
* hood 에서 typeless 템플릿은 index 를 만들때 더미 type `_doc` 를 사용한다.
* typeless 템플릿이 typed index 생성 호출과 함께 사용되거나, typed 템플릿이 typeless index 생성 호출과 함께 사용되면, 템플릿은 계속 적용되지만, idex 생성 호출은 type 이 있는지 없는지 결정해야 한다.
* 아래 예를 보면, `index-1-01` 는 typeless 템플릿과 일치하지만 type이 있고, `index-2-01` 는 type 정의 템플릿과 일치하지만 typeless 이다.
* `index-1-01`, `index-2-01` 둘다 일치 하는 템플릿에서 `foo` 필드를 상속한다.
```json
PUT _template/template1
{
"index_patterns":[ "index-1-*" ],
"mappings": {
"properties": {
"foo": {
"type": "keyword"
}
}
}
}
PUT _template/template2?include_type_name=true
{
"index_patterns":[ "index-2-*" ],
"mappings": {
"type": {
"properties": {
"foo": {
"type": "keyword"
}
}
}
}
}
PUT index-1-01?include_type_name=true
{
"mappings": {
"type": {
"properties": {
"bar": {
"type": "long"
}
}
}
}
}
PUT index-2-01
{
"mappings": {
"properties": {
"bar": {
"type": "long"
}
}
}
}
include_type_name
파라미터는 index 생성과 같은 index APIs 에서 꼭 지정해야 한다.
bulk
, update
와 같은 typeless document APIs 는 7.0 에서만 사용할 수 있고, 6.8 노드에선 동작하지 않는다.
terms
과 같은 document lookup 도 typeless 일 경우 동일하다.
https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html#_alternatives_to_mapping_types
Removal of mapping types
What are mapping types?
twitter
index 는user
타입과tweet
타입을 가질 수 있다.user
타입의 필드는full_name
,user_name
,email
tweet
타입의 필드는content
,tweeted_at
,user_name
_type
meta-field 가 있고, URL 에서 type 이름을 지정할 수 있다._type
필드는 document 의_id
와 결합하여_uid
필드를 만들기 때문에, 동일한_id
를 가진 다른 타입의 documents 가 같은 인덱스에 존재할 수 있다.question
타입의 문서는answer
타입의 문서의 부모일 수 있다.Why are mapping types being removed?
user
타입에서user_name
필드는tweet
타입의user_name
필드는 정확히 동일한 필드에 저장되며, 두user_name
필드는 같은 mapping(definition) 을 양쪽 타입에서 가져야 한다.deleted
필드를date
로 바꾸고자 하면, 같은 인덱스의 다른 타입에선boolean
필드로 되고자 하면 좌절된다.Alternatives to mapping types
Index per document type
twitter
인덱스에 저장 대신에, tweets 는tweets
인덱스로 users 는user
인덱스로 저장한다.users
는 줄이고,tweets
는 늘릴수 있다.Custom type field
_type
과 비슷하게 동작하는 커스텀type
필드 정의가 가능하다.user
/tweet
예제를 보면 원래 워크플로우는 다음과 같다.PUT twitter/user/kimchy { "name": "Shay Banon", "user_name": "kimchy", "email": "shay@kimchy.com" }
PUT twitter/tweet/1 { "user_name": "kimchy", "tweeted_at": "2017-10-24T09:00:00Z", "content": "Types are going away" }
GET twitter/tweet/_search { "query": { "match": { "user_name": "kimchy" } } }
Parent/Child without mapping types
Schedule for removal of mapping types
Elasticsearch 5.6.0
index.mapping.single_type: true
로 설정 되면, single-type-per-index 동작이 활성화 되고, 6.0 에서 시행될것이다.Elasticsearch 6.x
_doc
이며, index APIs 7.0 에서와 같은 path 를 갖는다. :PUT {index}/_doc/{id}
과POST {index}/_doc
_type
이름읋 더이상_id
와 결합하여_uid
필드를 생성하지 않는다._uid
필드는_id
필드의 alias 가 되었다._default_
매핑 타입이 deprecated 되었다include_type_name
을 설정하지 않으면 deprecation warning 결과가 나온다. 명시적인 type 이 없는 indices 는 더미 타입 이름인_doc
를 사용한다.Elasticsearch 7.x
type
를 요구하지 않는다. 새 인덱스 APIs 는 명시적일 때에는PUT {index}/_doc/{id}
이고, 자동 생성된 ids 에 대해서는POST {index}/_doc
이다. 7.0 에서_doc
는 path 의 영구적인 부분이며, 문서 타입이 아닌 엔드포인트 name 을 표현한다.include_type_name
파라미터는 defaultfalse
이다. 파라미터를 설정하면 deprecation warning 이 발생한다._default_
매핑 타입은 제거되었다.Elasticsearch 8.x
include_type_name
파라미터는 제거 되었다.