У меня есть JSON с вложенными объектами, детализирующими лауреатов Нобелевской премии.Победители агрегируются по годам и по категориям.например, фрагмент 1 - Лауреаты Нобелевской премии по физике за 2018
- Как правильно обрабатывать такую структуру данных в ElasticSearch?
- Должен ли я сгладить вседанные и введите их, используя различные вызовы REST, такие как фрагмент 2?
- Имеет ли ElasticSearch внутреннюю функцию для сопоставления и выравнивания объектов?
Если я использую сопоставление в фрагменте 3 и импортируюJSON, я получаю вложенные документы внутри документа _doc.
Есть ли способ сохранить и отобразить исходный вложенный JSON, сказав ElasticSearch, чтобы сгладить данные, аналогично тому, что вы получили бы из CSV-файла
Ссылка на тот же API, но в виде CSV-файла , как показаново фрагменте 4
Спасибо.
Фрагмент 1: JSON с вложенными объектами победителей
{
"prizes": [
{
"year": "2018",
"category": "physics",
"overallMotivation": "“for groundbreaking inventions in the field of laser physics”",
"laureates": [
{
"id": "960",
"firstname": "Arthur",
"surname": "Ashkin",
"motivation": ""for the optical tweezers and their application to biological systems"",
"share": "2"
},
{
"id": "961",
"firstname": "Gérard",
"surname": "Mourou",
"motivation": ""for their method of generating high-intensity, ultra-short optical pulses"",
"share": "4"
},
{
"id": "962",
"firstname": "Donna",
"surname": "Strickland",
"motivation": ""for their method of generating high-intensity, ultra-short optical pulses"",
"share": "4"
}
]
}
]
}
Фрагмент 2: три отдельных вызова REST для вставки плоской записи
PUT /nobel1/_doc/960
{
"year": "2018",
"category": "physics",
"overallMotivation": "“for groundbreaking inventions in the field of laser physics”",
"id": "960",
"firstname": "Arthur",
"surname": "Ashkin",
"motivation": "for the optical tweezers and their application to biological systems",
"share": "2"
}
PUT /nobel1/_doc/961
{
"year": "2018",
"category": "physics",
"overallMotivation": "“for groundbreaking inventions in the field of laser physics”",
"id": "961",
"firstname": "Gérard",
"surname": "Mourou",
"motivation": "for their method of generating high-intensity, ultra-short optical pulses",
"share": "4"
}
PUT /nobel1/_doc/962
{
"year": "2018",
"category": "physics",
"overallMotivation": "“for groundbreaking inventions in the field of laser physics”",
"id": "962",
"firstname": "Donna",
"surname": "Strickland",
"motivation": "for their method of generating high-intensity, ultra-short optical pulses",
"share": "4"
}
Фрагмент 3: сопоставление ElasticSearch для вложенных объектов
PUT /nobel
{
"mappings": {
"_doc": {
"properties": {
"year": {
"type": "integer"
},
"category": {
"type": "keyword",
"fields":{
"raw": {
"type": "text"
}
}
},
"overallMotivation": {
"type": "text"
},
"laureates": {
"type": "nested",
"properties": {
"id": {
"type": "integer"
},
"firstname": {
"type": "text"
},
"surname": {
"type": "text"
},
"motivation": {
"type": "text"
},
"share": {
"type": "integer"
}
}
}
}
}
}
}
Фрагмент 4: API лауреатов Нобелевской премии в формате CSV
year,category,overallMotivation,id,firstname,surname,motivation,share
2018,physics,"“for groundbreaking inventions in the field of laser physics”",960,Arthur,Ashkin,"""for the optical tweezers and their application to biological systems""",2
2018,physics,"“for groundbreaking inventions in the field of laser physics”",961,Gérard,Mourou,"""for their method of generating high-intensity, ultra-short optical pulses""",4
2018,physics,"“for groundbreaking inventions in the field of laser physics”",962,Donna,Strickland,"""for their method of generating high-intensity, ultra-short optical pulses""",4