반응형
    
    
    
  @ 테스트 후 정리
- Setting or Mapping 은 최초 index (table) 생성시 적용이 됩니다.
- 중간에 끼어 넣기 안됨 , 최초 생성하면서 설정 해줘야함 .
- spring data @Document 객체에 @Setting, @Mapping annotation을 통해서 간단하게 연결 할 수 있습니다.
- Setting와 Mapping 에는 "setting" or "mapping" 노드를 포함하지 않는다. <-- 포함시 세팅 안됨
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "idx_es_address", createIndex = true)
@Setting(settingPath = "/elasticsearch/settings/settings.json")
@Mapping(mappingPath = "/elasticsearch/mappings/mappings.json")
public class EsAddressVO {
    //고객코드
    @Id
    private String cuscode;
    private String areacode;
    //신주소
    private String naddr;
    //구주소
    private String oaddr;
    
}
@Setting /resources/elasticsearch/settings/settings.json
- tokenizer와 analyzer 세팅함
{
  "analysis": {
    "tokenizer": {
      "nori_none": {
        "type": "nori_tokenizer",
        "decompound_mode": "none"
      },
      "nori_discard": {
        "type": "nori_tokenizer",
        "decompound_mode": "discard"
      },
      "nori_mixed": {
        "type": "nori_tokenizer",
        "decompound_mode": "mixed"
      }
    },
    "analyzer": {
      "korean": {
        "type": "nori",
        "stopwords": "_korean_"
      }
    }
  }
}위 tokenizer 에 대한 자세한 부분들은 기술문서 참고 할것
@Mapping /resources/elasticsearch/mappings/mappings.json
기본적으로 spring에서 mapping을 지정하지 않더라도 기본 mapping을 해주지만
nori 한글 검색을 사용하기 위해서 oaddr 필드에 setting.jsoin에서 등록해둔 korean <-- analyzer를 지정
{
    "properties": {
      "oaddr": {
        "type": "text",
        "analyzer": "korean"
      }
    }
}
kibana console에서 확인하는 방법
GET idx_es_addres/_settings
{
  "idx_es_address" : {
    "settings" : {
      "index" : {
        "routing" : {
          "allocation" : {
            "include" : {
              "_tier_preference" : "data_content"
            }
          }
        },
        "number_of_shards" : "1",
        "provided_name" : "idx_es_address",
        "creation_date" : "1606194598534",
        "analysis" : {
          "analyzer" : {
            "korean" : {
              "type" : "nori",
              "stopwords" : "_korean_"
            }
          },
          "tokenizer" : {
            "nori_discard" : {
              "type" : "nori_tokenizer",
              "decompound_mode" : "discard"
            },
            "nori_mixed" : {
              "type" : "nori_tokenizer",
              "decompound_mode" : "mixed"
            },
            "nori_none" : {
              "type" : "nori_tokenizer",
              "decompound_mode" : "none"
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "mxGr5zJOTrW5Gp9-n4HjHQ",
        "version" : {
          "created" : "7100099"
        }
      }
    }
  }
}
GET idx_es_address/_mapping
{
  "idx_es_address" : {
    "mappings" : {
      "properties" : {
        "_class" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "areacode" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "cuscode" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "naddr" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "oaddr" : {
          "type" : "text",
          "analyzer" : "korean"
        }
      }
    }
  }
}
반응형
    
    
    
  'Elasticsearch' 카테고리의 다른 글
| elasticsearch default page size 기본 페이징 사이즈 (0) | 2020.11.25 | 
|---|---|
| @Setting, @Mapping nori 설정 (0) | 2020.11.25 | 
| elasticsearch srping boot connection 설정 (0) | 2020.11.24 | 
| elasticsearch 버전별 호환체크해두기, pom 버전 확인 (0) | 2020.11.23 | 
| Elasticsearch 아이디 /비밀번호 설정 (0) | 2020.11.23 | 
 
							 
							