중첩 및 객체 필드 유형
Elasticsearch가 JSON 객체와 배열을 처리하는 방식, 기본 객체 유형이 데이터를 평탄화하는 이유, 그리고 중첩 유형이 객체 배열 내부의 관계를 보존하는 방식을 익혀 보세요.
중첩 및 객체 필드 유형은(는) CoddyKit의 무료 Elasticsearch & Full Text Search Systems 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Elasticsearch & Full Text Search Systems 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Elasticsearch & Full Text Search Systems 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Storing Structured Data
Real-world documents often contain nested structures: a blog post with comments, a product with variants, or an order with line items. Elasticsearch must decide how to index these JSON objects so they stay searchable.
This lesson covers the two main approaches: the default object type and the specialized nested type.
The Default object Type
By default, any JSON object inside a document is mapped as the object type. Elasticsearch flattens the inner fields into dotted paths.
A field author.name simply becomes a normal Lucene field. This is efficient and works perfectly for single objects.
PUT my_index/_doc/1
{
"author": { "first": "Jane", "last": "Doe" }
}How Flattening Looks
Internally the object above is stored as two flat fields: author.first = Jane and author.last = Doe. The hierarchy is only conceptual; Lucene sees independent fields.
This is fine until you have an array of objects.
The Flattening Problem
Consider an array of users. After flattening, Elasticsearch loses the link between which first name belongs to which last name.
The arrays become user.first = [Alice, John] and user.last = [White, Smith] separately.
PUT my_index/_doc/2
{
"user": [
{ "first": "Alice", "last": "White" },
{ "first": "John", "last": "Smith" }
]
}Why It Matters
A query for first = Alice AND last = Smith would incorrectly match the document above, because the cross-object relationship is gone. The values are pooled together.
The nested type solves this.
Declaring a Nested Field
Set the field type to nested in the mapping. Each object in the array is then indexed as a hidden, separate Lucene document, preserving its internal field relationships.
PUT my_index
{
"mappings": {
"properties": {
"user": { "type": "nested" }
}
}
}Querying Nested Fields
You must use a nested query and specify the path. Conditions inside are evaluated against a single sub-document, so cross-object false matches disappear.
GET my_index/_search
{
"query": {
"nested": {
"path": "user",
"query": {
"bool": { "must": [
{ "match": { "user.first": "Alice" }},
{ "match": { "user.last": "Smith" }}
]}
}
}
}
}Inner Hits
Add inner_hits to a nested query to return which specific sub-document(s) matched, not just the parent document. This is essential for highlighting the relevant array element.
"nested": {
"path": "user",
"inner_hits": {},
"query": { "match": { "user.first": "Alice" } }
}Costs of Nested
Nested fields are powerful but have trade-offs:
- Each array element is a separate Lucene doc, increasing index size.
- Updating one element re-indexes the whole parent document.
- Deeply nested or large arrays can hurt performance.
Use the index.mapping.nested_objects.limit setting to cap counts.
Nested vs join
For tightly coupled data that updates together, nested is ideal. For independently updated, high-cardinality relationships, consider the join (parent-child) field type instead, which decouples updates at a higher query cost.
When to Choose Which
Use object when arrays do not require cross-field correlation. Use nested when you must match multiple fields within the same array element. Defaulting to nested for everything wastes resources.
Quick Check
Test your understanding of nested mappings.
Recap
You learned how Elasticsearch indexes JSON objects:
- The default
objecttype flattens fields and pools array values. - The
nestedtype indexes each array element separately to preserve relationships. - Query nested fields with the
nestedquery plus apath, and useinner_hitsto find matching elements. - Nested types cost more storage and require full re-indexing on element updates.
자주 묻는 질문
“중첩 및 객체 필드 유형” 강의는 무료인가요?
네 — “중첩 및 객체 필드 유형” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Elasticsearch & Full Text Search Systems 강의 전체를 잠금 해제할 수 있습니다. Elasticsearch & Full Text Search Systems 강의에는 총 4개의 강의가 포함되어 있습니다.
“중첩 및 객체 필드 유형”에서 뭘 배우나요?
Elasticsearch가 JSON 객체와 배열을 처리하는 방식, 기본 객체 유형이 데이터를 평탄화하는 이유, 그리고 중첩 유형이 객체 배열 내부의 관계를 보존하는 방식을 익혀 보세요. 브라우저에서 직접 실행하는 실습 코드로 Elasticsearch & Full Text Search Systems을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Elasticsearch & Full Text Search Systems을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Elasticsearch & Full Text Search Systems은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“중첩 및 객체 필드 유형” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Elasticsearch & Full Text Search Systems 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Elasticsearch & Full Text Search Systems 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 필드 매핑 사용자 지정
- 동적 매핑과 명시적 매핑 비교
- 인덱스 템플릿 및 별칭
- 중첩 및 객체 필드 유형