ElasticStack - Mapping

정명진·2023년 2월 15일
0

ElasticSearch는 자동으로 다이나믹 매핑을 지원한다. 원래는 각 필드에 대한 값들에 대해 속성 설정 즉 매핑이 필요한데 설정 매핑을 해주지 않아도 자동으로 추론해 매핑을 하는것이다.

{
  "index2" : {
    "mappings" : {
      "properties" : {
        "age" : {
          "type" : "long"
        },
        "gender" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

이런식으로 말이다. 하지만 내가 만약 필드에 대해서 매핑을 커스텀해서 지정해주면 해당 설정에맞게 인덱스를 생성한다.

{
  "properties" : {
    "id" : {"type" : "keyword"},
    "title" : {"type" : "text", "fields": {"kor":  {"type":  "text", "analyzer": "korean"}, "ngram":  {"type" : "text", "analyzer":  "my_ngram_analyzer"}}},
    "musicalDateTime" : {"type" : "keyword"},
    "place" : {"type" : "text", "fields": {"kor":  {"type":  "text", "analyzer": "korean"}, "ngram":  {"type" : "text", "analyzer":  "my_ngram_analyzer"}}},
    "imageUrl" : {"type" : "text"},
    "performanceType" : {"type" : "text", "fields": {"kor":  {"type":  "text", "analyzer": "korean"}, "ngram":  {"type" : "text", "analyzer":  "my_ngram_analyzer"}}}
  }
}

인덱스를 확인해보면

{
    "performance": {
        "mappings": {
            "properties": {
                "_class": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "endDate": {
                    "type": "date"
                },
                "id": {
                    "type": "keyword"
                },
                "imageUrl": {
                    "type": "text"
                },
                "musicalDateTime": {
                    "type": "keyword"
                },
                "performanceType": {
                    "type": "text",
                    "fields": {
                        "kor": {
                            "type": "text",
                            "analyzer": "korean"
                        },
                        "ngram": {
                            "type": "text",
                            "analyzer": "my_ngram_analyzer"
                        }
                    }
                },
                "place": {
                    "type": "text",
                    "fields": {
                        "kor": {
                            "type": "text",
                            "analyzer": "korean"
                        },
                        "ngram": {
                            "type": "text",
                            "analyzer": "my_ngram_analyzer"
                        }
                    }
                },
                "startDate": {
                    "type": "date"
                },
                "title": {
                    "type": "text",
                    "fields": {
                        "kor": {
                            "type": "text",
                            "analyzer": "korean"
                        },
                        "ngram": {
                            "type": "text",
                            "analyzer": "my_ngram_analyzer"
                        }
                    }
                }
            }
        }
    }
}

다음과 같이 사용자 지정에 맞춘 매핑 결과를 볼 수 있다.

profile
개발자로 입사했지만 정체성을 잃어가는중... 다시 준비 시작이다..

0개의 댓글