Copy to 매핑 파라미터
Copy to 매핑 파라미터
copy_to 파라미터는 여러 필드의 값을 그룹 필드로 복사해 단일 필드로 쿼리할 수 있게 해줘요. 여러 필드를 자주 검색하고 쿼리를 단순화하고 싶을 때 유용해요.
출처: 문서
본문
copy_to 파라미터는 여러 필드의 값을 그룹 필드로 복사해 단일 필드로 쿼리할 수 있게 해줍니다. 여러 필드에 걸쳐 자주 검색하고 쿼리를 단순화하고 싶을 때 유용합니다.
다음의 중요한 고려 사항을 참고하세요.
- 복사 중에는 분석 중 생성된 토큰이 아니라 원시 필드 값이 복사됩니다.
- 원본
_source필드는 복사된 값을 반영하도록 수정되지 않습니다. "copy_to": ["field_1", "field_2"]구문을 사용해 같은 값을 여러 필드로 복사할 수 있습니다.- 중간 필드를 통해 재귀적으로 복사할 수는 없습니다. 예를 들어
field_1이field_2로 복사되고field_2가field_3으로 복사된다면,field_1에 인덱싱해도 값이field_3에 나타나지 않습니다. 대신 원본 필드에서 여러 대상 필드로 직접copy_to를 사용하세요.
예제
다음 예제들은 copy_to 파라미터를 사용하는 방법을 보여 줍니다.
기본 copy_to 사용법
first name과 last name을 full_name 필드로 복사하는 인덱스를 만듭니다.
PUT /user_profiles
{
"mappings": {
"properties": {
"first_name": {
"type": "text",
"copy_to": "full_name"
},
"last_name": {
"type": "text",
"copy_to": "full_name"
},
"full_name": {
"type": "text"
}
}
}
}
이름 필드가 분리된 문서를 인덱싱합니다.
PUT /user_profiles/_doc/1
{
"first_name": "Jane",
"last_name": "Doe"
}
first_name과 last_name 필드는 여전히 개별적으로 쿼리할 수 있지만, full_name 필드를 사용하면 두 이름을 함께 검색할 수 있습니다. 결합 필드로 검색하려면 다음 요청을 보내세요. and 연산자는 두 용어가 모두 일치해야 합니다.
GET /user_profiles/_search
{
"query": {
"match": {
"full_name": {
"query": "Jane Doe",
"operator": "and"
}
}
}
}
응답에는 매칭되는 문서가 포함됩니다.
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.26152915,
"hits": [
{
"_index": "user_profiles",
"_id": "1",
"_score": 0.26152915,
"_source": {
"first_name": "Jane",
"last_name": "Doe"
}
}
]
}
}
여러 대상 필드로 복사
필드 내용을 여러 대상 필드로 복사하려면 title 필드를 searchable_content와 display_text 필드 양쪽으로 복사하는 인덱스를 만듭니다. body 필드는 searchable_content로만 복사됩니다.
PUT /content_library
{
"mappings": {
"properties": {
"title": {
"type": "text",
"copy_to": ["searchable_content", "display_text"]
},
"body": {
"type": "text",
"copy_to": "searchable_content"
},
"searchable_content": {
"type": "text"
},
"display_text": {
"type": "text"
}
}
}
}
title과 body 필드를 포함하는 문서를 인덱싱합니다.
PUT /content_library/_doc/1
{
"title": "OpenSearch Documentation Guide",
"body": "This comprehensive guide covers mapping parameters and their usage in OpenSearch."
}
searchable_content 필드를 사용해 title과 body 내용을 모두 검색할 수 있습니다.
GET /content_library/_search
{
"query": {
"match": {
"searchable_content": "OpenSearch mapping parameters"
}
}
}
응답에는 매칭되는 문서가 포함됩니다. 문서의 원본 _source 필드에는 여전히 title과 body 필드만 포함되어 있습니다.
{
"took": 21,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.44133043,
"hits": [
{
"_index": "content_library",
"_id": "1",
"_score": 0.44133043,
"_source": {
"title": "OpenSearch Documentation Guide",
"body": "This comprehensive guide covers mapping parameters and their usage in OpenSearch."
}
}
]
}
}