Elasticsearch store field

JunMyung Lee·2023년 2월 27일
0

Elasticsearch

목록 보기
10/37

기본적으로 필드 값은 검색 가능하도록 색인 되지만, 저장되지는 않는다.

Why do we use it?

특정 상황에서는 필드를 저장하는 것이 합리적일 수 있다. 매우 큰 내용 필드를 가진 문서가 있는 경우, _source 필드에서 원하는 필드를 추출하지 않고 store_field로 지정된 필드만 검색하여 색인된 값을 직접 읽어와서 압축과 해제의 단계를 거치지 않는다.

해당 예시에서는 title, date 필드가 매우큰 텍스트로 이루어져(전자결제 문서같은) 있다고 가정

PUT my-index-000001
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "store": true 
      },
      "date": {
        "type": "date",
        "store": true 
      },
      "content": {
        "type": "text"
      }
    }
  }
}

PUT my-index-000001/_doc/1
{
  "title":   "Some short title",
  "date":    "2015-01-01",
  "content": "A very long content field..."
}
GET my-index-000001/_search
{
  "_source": false,
  "stored_fields": [ "title", "date"] 
}

"hits": [
  {
	"_index": "my-index-000001",
	"_id": "1",
	"_score": 1,
	"fields": {
	  "date": [
		"2015-01-01T00:00:00.000Z"
	  ],
	  "title": [
		"Some short title"
	  ]
	}
  }
]
GET my-index-000001/_search

"hits": [
  {
	"_index": "my-index-000001",
	"_id": "1",
	"_score": 1,
	"_source": {
	  "title": "Some short title",
	  "date": "2015-01-01",
	  "content": "A very long content field..."
	}
  }
]

저장된 필드가 배열로 반환됨

원래 필드 값이 단일 값인지, 다중 값인지, 빈 배열인지 알 수 없으므로 일관성을 위해 저장된 필드는 항상 배열로 반환
원래 값이 필요한 경우 _source 필드에서 검색

0개의 댓글