Generating data using index mappings
출처: 문서
본문
인덱스 매핑을 사용해 데이터 생성하기
OpenSearch 인덱스 매핑을 사용해 합성 데이터를 생성할 수 있어요. 이 방식은 자동화와 커스터마이징 사이의 균형을 잡아 줘요.
이 방법을 사용하려면 OpenSearch 인덱스 매핑을 JSON 파일로 저장해 주세요:
{
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "standard",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"description": {
"type": "text"
},
"price": {
"type": "float"
},
"created_at": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"is_available": {
"type": "boolean"
},
"category_id": {
"type": "integer"
},
"tags": {
"type": "keyword"
}
}
},
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
}
}
OpenSearch Benchmark는 복잡도와 관계없이 유효한 인덱스 매핑이라면 어떤 것이든 동작해요. 다음과 같은 더 복잡한 매핑도 제공할 수 있어요:
매핑
{: .text-delta}{
"mappings": {
"dynamic": "strict",
"properties": {
"user": {
"type": "object",
"properties": {
"id": {
"type": "keyword"
},
"email": {
"type": "keyword"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
},
"completion": {
"type": "completion"
}
},
"analyzer": "standard"
},
"address": {
"type": "object",
"properties": {
"street": {
"type": "text"
},
"city": {
"type": "keyword"
},
"state": {
"type": "keyword"
},
"zip": {
"type": "keyword"
},
"location": {
"type": "geo_point"
}
}
},
"preferences": {
"type": "object",
"dynamic": true
}
}
},
"orders": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"date": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"amount": {
"type": "scaled_float",
"scaling_factor": 100
},
"status": {
"type": "keyword"
},
"items": {
"type": "nested",
"properties": {
"product_id": {
"type": "keyword"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"quantity": {
"type": "short"
},
"price": {
"type": "float"
},
"categories": {
"type": "keyword"
}
}
},
"shipping_address": {
"type": "object",
"properties": {
"street": {
"type": "text"
},
"city": {
"type": "keyword"
},
"state": {
"type": "keyword"
},
"zip": {
"type": "keyword"
},
"location": {
"type": "geo_point"
}
}
}
}
},
"activity_log": {
"type": "nested",
"properties": {
"timestamp": {
"type": "date"
},
"action": {
"type": "keyword"
},
"ip_address": {
"type": "ip"
},
"details": {
"type": "object",
"enabled": false
}
}
},
"metadata": {
"type": "object",
"properties": {
"created_at": {
"type": "date"
},
"updated_at": {
"type": "date"
},
"tags": {
"type": "keyword"
},
"source": {
"type": "keyword"
},
"version": {
"type": "integer"
}
}
},
"description": {
"type": "text",
"analyzer": "english",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
},
"standard": {
"type": "text",
"analyzer": "standard"
}
}
},
"ranking_scores": {
"type": "object",
"properties": {
"popularity": {
"type": "float"
},
"relevance": {
"type": "float"
},
"quality": {
"type": "float"
}
}
},
"permissions": {
"type": "nested",
"properties": {
"user_id": {
"type": "keyword"
},
"role": {
"type": "keyword"
},
"granted_at": {
"type": "date"
}
}
}
}
},
"settings": {
"number_of_shards": 3,
"number_of_replicas": 2,
"analysis": {
"analyzer": {
"email_analyzer": {
"type": "custom",
"tokenizer": "uax_url_email",
"filter": ["lowercase", "stop"]
}
}
}
}
}
데이터 생성하기
인덱스 매핑을 사용해 합성 데이터를 생성하려면 generate-data 서브커맨드를 사용하고, 필요한 인덱스 매핑 파일, 인덱스 이름, 출력 경로, 생성할 총 데이터 양을 지정해 주세요:
osb generate-data --index-name <NAME_OF_DATA_CORPORA> --index-mappings <PATH_TO_INDEX_MAPPINGS> --output-path <DESIRED_OUTPUT_PATH> --total-size <TOTAL_SIZE_OF_DATA_CORPORA_GENERATED_IN_GB>
{% include copy.html %}
사용 가능한 파라미터와 설명의 전체 목록은 generate-data 커맨드 레퍼런스를 참고하세요.
예시 출력
다음은 100 GB의 데이터를 생성할 때의 예시 출력이에요:
____ _____ __ ____ __ __
/ __ \____ ___ ____ / ___/___ ____ ___________/ /_ / __ )___ ____ _____/ /_ ____ ___ ____ ______/ /__
/ / / / __ \/ _ \/ __ \\__ \/ _ \/ __ `/ ___/ ___/ __ \ / __ / _ \/ __ \/ ___/ __ \/ __ `__ \/ __ `/ ___/ //_/
/ /_/ / /_/ / __/ / / /__/ / __/ /_/ / / / /__/ / / / / /_/ / __/ / / / /__/ / / / / / / / / /_/ / / / ,<
\____/ .___/\___/_/ /_/____/\___/\__,_/_/ \___/_/ /_/ /_____/\___/_/ /_/\___/_/ /_/_/ /_/ /_/\__,_/_/ /_/|_|
/_/
[NOTE] ✨ Dashboard link to monitor processes and task streams: [http://127.0.0.1:8787/status]
[NOTE] ✨ For users who are running generation on a virtual machine, consider SSH port forwarding (tunneling) to localhost to view dashboard.
[NOTE] Example of localhost command for SSH port forwarding (tunneling) from an AWS EC2 instance:
ssh -i <PEM_FILEPATH> -N -L localhost:8787:localhost:8787 ec2-user@<DNS>
Total GB to generate: [1]
Average document size in bytes: [412]
Max file size in GB: [40]
100%|███████████████████████████████████████████████████████████████████| 100.07G/100.07G [3:35:29<00:00, 3.98MB/s]
Generated 24271844660 docs in 12000 seconds. Total dataset size is 100.21GB.
✅ Visit the following path to view synthetically generated data: /home/ec2-user/
-----------------------------------
[INFO] ✅ SUCCESS (took 272 seconds)
-----------------------------------
고급 설정
YAML 설정 파일을 만들면 합성 데이터가 생성되는 방식을 제어할 수 있어요. 다음은 MappingGenerationValues 파라미터에 커스텀 규칙을 정의하는 설정 파일 예시예요:
MappingGenerationValues:
# For users who want more granular control over how data is generated when providing an OpenSearch mapping
generator_overrides:
# Overrides all instances of generators with these settings. Specify type and params
integer:
min: 0
max: 20
long:
min: 0
max: 1000
float:
min: 0.0
max: 1.0
double:
min: 0.0
max: 2000.0
date:
start_date: "2020-01-01"
end_date: "2023-01-01"
format: "yyyy-mm-dd"
text:
must_include: ["lorem", "ipsum"]
keyword:
choices: ["alpha", "beta", "gamma"]
field_overrides:
# Specify field name as key of dict. For its values, specify generator and its params. Params must adhere to existing params for each generator
# For nested fields, use dot notation: Example preferences.allergies if allergies is a subfield of preferences object
title:
generator: generate_keyword
params:
choices: ["Helly R", "Mark S", "Irving B"]
promo_codes:
generator: generate_keyword
params:
choices: ["HOT_SUMMER", "TREATSYUM!"]
# Nested fields, use dot notation
orders.items.product_id:
generator: generate_keyword
params:
choices: ["Python", "English"]
{% include copy.html %}
MappingGenerationValues는 다음 파라미터를 지원해요.
| 파라미터 | 설명 |
|---|---|
generator_overrides |
특정 OpenSearch 필드 타입에 대한 커스텀 제너레이터 규칙을 정의해요. 해당 타입을 사용하는 모든 필드는 이 규칙을 따라요. 제너레이터 오버라이드 파라미터를 참고하세요. |
field_overrides |
필드 이름별로 개별 필드에 대한 제너레이터 규칙을 정의해요. 명시적으로 나열된 필드에만 적용돼요. 중첩 필드에는 점 표기법을 사용하세요(예: orders.items.product_id). 필드 오버라이드 파라미터를 참고하세요. |
generator_overrides와 field_overrides가 모두 있으면 field_overrides가 우선 적용돼요.
{: .important}
제너레이터 오버라이드 파라미터
generator_overrides의 각 OpenSearch 필드 타입에 사용할 수 있는 파라미터는 다음과 같아요.
| 필드 타입 | 파라미터 |
|---|---|
integer, long, short, byte |
min, max |
float, double |
min, max, round(반올림할 소수점 자릿수) |
date |
start_date, end_date, format |
text |
must_include(생성된 텍스트에 포함할 용어 배열) |
keyword |
choices(무작위로 선택할 키워드 배열) |
필드 오버라이드 파라미터
field_overrides에서 사용할 수 있는 제너레이터와 파라미터는 다음과 같아요.
| 제너레이터 | 파라미터 |
|---|---|
generate_text |
must_include(생성된 텍스트에 포함할 용어 배열) |
generate_keyword |
choices(무작위로 선택할 키워드 배열) |
generate_integer |
min, max |
generate_long |
min, max |
generate_short |
min, max |
generate_byte |
min, max |
generate_float |
min, max, round(반올림할 소수점 자릿수) |
generate_double |
min, max |
generate_boolean |
N/A |
generate_date |
format, start_date, end_date |
generate_ip |
N/A |
generate_geo_point |
N/A |
generate_knn_vector |
dimension, sample_vectors, noise_factor, distribution_type, normalize. 벡터 생성하기를 참고하세요. |
generate_sparse_vector |
num_tokens, min_weight, max_weight, token_id_start, token_id_step. 벡터 생성하기를 참고하세요. |
설정 사용하기
설정 파일을 사용하려면 --custom-config 파라미터에 전체 경로를 지정해 주세요:
osb generate-data --index-name <NAME_OF_DATA_CORPORA> --index-mappings <PATH_TO_INDEX_MAPPINGS> --output-path <DESIRED_OUTPUT_PATH> --total-size <TOTAL_SIZE_OF_DATA_CORPORA_GENERATED_IN_GB> --custom-config ~/Desktop/sdg-config.yml
{% include copy.html %}