A common structure for hierarchical data in ElasticSearch is to use nested objects.
For example, let's say you have a dataset of employees and their departments. Each department can have multiple employees, and each employee has a unique identifier, as well as their name, job title, etc.
You could structure your ElasticSearch index as follows:
{
"mappings": {
"properties": {
"department": {
"type": "text"
},
"employees": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"name": {
"type": "text"
},
"job_title": {
"type": "text"
},
"salary": {
"type": "integer"
}
}
}
}
}
}
In this example, the "employees" field is a nested object containing properties for each employee. This allows you to easily query and filter by department, as well as by individual employees within a department.
To create a document in this index, you could use the following JSON structure:
{
"department": "HR",
"employees": [
{
"id": "123",
"name": "John Smith",
"job_title": "HR Manager",
"salary": 100000
},
{
"id": "456",
"name": "Jane Doe",
"job_title": "HR Representative",
"salary": 50000
}
]
}
This structure allows you to easily retrieve all employees in a department, search for specific employees by name or ID, and aggregate data by department or by employee.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-04 23:46:15 +0000
Seen: 16 times
Last updated: Jun 04 '23
Can you choose the values from a row depending on whether another row is distinct?
How can the columns be transformed into a multi-level structure?
What are the varying shapes in the Tensorflow Dataset from_generator?
What is the proper way to structure computed land measurement using Excel?
Can the grid pattern be obtained by modifying the hollow star pattern?
How can the schema structure of Firestore be exported to a JSON file?
What CNN structure is appropriate for the classification of extremely small images?
Is it possible to have an unordered map consisting of a structure that has an expanding linked list?
How can JSON be decoded while using a universal interface as a field?