아 어제 당연히 keyword타입으로 ES에 데이터가 들어갈거라고 생각 못하고 한게 실수였다ㅠㅠ 어제 만든 타입들이 모두 text타입으로 들어가서 데이터들의 타입을 모두 바꿔줘야했댜... 찾아보니 보통 한번 넣은 데이터는 그것만 바꿀 수 없고 reindex을 통해 다시 인덱스를 생성해줘야한다고 한다. 😭
새로운 인덱스를 만든다.
REQUEST
-URL
PUT https://{elasticsearch host주소}/{추가할 인덱스명}
성공시 RESPONSE
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "product_categories"
}
새로 만든 인덱스 확인
REQUEST
GET https://{elasticsearch host주소}/{추가할 인덱스명}?pretty
성공시 RESPONSE
{
"{추가한 인덱스명}": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "{추가한 인덱스명}",
"creation_date": "1648110877312",
"number_of_replicas": "1",
"uuid": "wzTiM9nqQoe9VxQHH4JUvQ",
"version": {
"created": "7140099"
}
}
}
}
}
RESPONSE 를 보면 mappings
라는 부분이 보이는데 그 부분에 인덱스에 넣을 데이터타입을 정의해줘야한다.
2번에서 말한 것처럼 위에서 추가한 인덱스에 매핑을 해줄것이다!
(*인덱스를 만들때 매핑도 가능하다.
→ https://www.elastic.co/guide/en/elasticsearch/reference/current/explicit-mapping.html#create-mapping)
REQUEST
-URL
PUT https://{elasticsearch host주소}/_mapping
-Body
{
"properties" : {
"field1" : {
"type" : "keyword"
},
"field2" : {
"type" : "integer"
}
}
}
성공시 RESPONSE
{
"acknowledged": true
}
다시 추가한 인덱스를 확인해보쟈!
REQUEST
GET https://{elasticsearch host주소}/{추가할 인덱스명}?pretty
성공시 RESPONSE
{
"{추가한 인덱스명}": {
"aliases": {},
"mappings": {
"properties": {
"field1": {
"type": "keyword"
},
"field2": {
"type": "integer"
}
}
},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "{추가한 인덱스명}",
"creation_date": "1648110877312",
"number_of_replicas": "1",
"uuid": "wzTiM9nqQoe9VxQHH4JUvQ",
"version": {
"created": "7140099"
}
}
}
}
}
mappings
을 보면 이전과 다르게 위에서 mapping작업을 한 properties가 저장되어있다!
이제 reindex를 진행한다!
(++추가: *reindex의 경우, ES클러스터의 부하가 높아진다. 한꺼번에 많은 데이터를 새로 인덱싱하기 때문인데, 때문에 이미 부하가 높다면 성능에 여유가 있는 지 확인 후에 실행하도록 하는 것이 좋다. 그리고 reindex의 최소화를 위해서는 index를 더 잘게 쪼개서 alias로 관리하는 편이 좋다고 한다.)
**REQUEST**
-URL
```
POST https://{elasticsearch host주소}/_reindex
```
-Body
```json
{
"source": {
"index": "{기존인덱스이름}"
},
"dest": {
"index": "{추가한인덱스이름}"
}
}
```
성공시 RESPONSE
{
"took": 196,
"timed_out": false,
"total": 2220,
"updated": 0,
"created": 2220,
"deleted": 0,
"batches": 3,
"version_conflicts": 0,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1.0,
"throttled_until_millis": 0,
"failures": []
}
기존 인덱스를 지운다!
REQUEST
DELETE https://{elasticsearch host주소}
성공시 RESPONSE
{
"acknowledged": true
}
끝!! 🙋♀️