One to many relation

Hello guys , please i need help urgennnt ,, ihave this mapping , normaly i should have data ,each item should have multipple detail_name, detail_description, type_name ,, but i have only one each item ,, this is my mapping {
"mappings": {
"dynamic": "false",
"_source": {
"enabled": true,
"includes": [
"created_at",
"updated_at",
"date",
"lang.keyword",
"source.id",
"source_type.keyword",
"source.name_fr",
"source.created_at",
"source.updated_at",
"source.logo_url",
"source.reach",
"source.reach.id",
"source.reach.source_name",
"source.reach.source_name.keyword",
"source.reach.reach_score.keyword",
"author",
"title",
"content",
"sentiment",
"source",
"source_type",
"source_name",
"__class_name",
"lang",
"detail",
"detail.name",
"detail.description",
"detail.created_at",
"detail.hashed_link",
"detail.type_id",
"detail_name",
"detail_description",
"detail_name.keyword",
"detail_description.keyword",
"type_name",
"type_name.keyword",
"type.type",
"type",
"type_id",
"type_id.keyword"
]
},
"properties": {
"__class_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"author": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256,
"index_options": "freqs"
}
},
"term_vector": "with_positions_offsets",
"fielddata": true
},
"category_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"index_options": "freqs",
"norms": true
}
},
"index_options": "offsets",
"term_vector": "with_positions_offsets",
"fielddata": true,
"fielddata_frequency_filter": {
"min": 0.01,
"max": 1,
"min_segment_size": 50
}
},
"created_at": {
"type": "date"
},
"date": {
"type": "date"
},
"detail": {
"type": "nested",
"properties": {
"created_at": {
"type": "date"
},
"description": {
"type": "text"
},
"hashed_link": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"name": {
"type": "text"
},
"type_id": {
"type": "long"
}
}
},
"detail_description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"detail_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"hashed_link": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "long"
},
"lang": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"lat": {
"type": "float"
},
"link": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"lon": {
"type": "float"
},
"reach": {
"properties": {
"date": {
"type": "date"
},
"id": {
"type": "long"
},
"reach_score": {
"type": "double"
},
"source_name": {
"type": "text"
}
}
},
"reach_score": {
"type": "float"
},
"sentiment": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"source": {
"properties": {
"created_at": {
"type": "date"
},
"id": {
"type": "long"
},
"logo_url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name_ar": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name_fr": {
"type": "text"
},
"reach": {
"properties": {
"date": {
"type": "date"
},
"id": {
"type": "long"
},
"reach_score": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"source_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"sourcetype_id": {
"type": "text"
},
"updated_at": {
"type": "date"
}
}
},
"source_id": {
"type": "long"
},
"source_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"source_type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"sourcetype": {
"properties": {
"name": {
"type": "text"
}
}
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256,
"index_options": "freqs"
}
},
"term_vector": "with_positions_offsets",
"fielddata": true
},
"type_id": {
"type": "long",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"type_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"updated_at": {
"type": "text"
}
}
}
}

Hi @imane_ajroudi,

Welcome to the community! Am I correct in my understanding that you want to model a relationship where for each document you can have many values for fields such as detail.description? Is there a relationship between the detail.name and detail.description values?

As covered in the documentation Elasticsearch doesn't have a dedicated array type, and fields support 0 or more values. Depending on how you want to search for multiple values you might want to consider either:

  1. Using the default functionality as covered in the link above.
  2. Model your data as a nested type, making sure to note the limitations of this approach.

Hope that helps!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.