# How can i create this indices?

**URL:** <https://discuss.elastic.co/t/how-can-i-create-this-indices/46928>\
**Category:** Elasticsearch\
**Created:** [April 11, 2016, 1:08am UTC](https://discuss.elastic.co/t/how-can-i-create-this-indices/46928 "2016-04-11T01:08:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![111116](https://avatars.discourse-cdn.com/v4/letter/1/13edae/32.png) [@111116](https://discuss.elastic.co/u/111116)\
**Post date:** [April 11, 2016, 1:08am UTC](https://discuss.elastic.co/t/how-can-i-create-this-indices/46928/1 "2016-04-11T01:08:08Z")

</div>

_(main subject is changed to companies)_  
_I don't have any budget. I'm student. I wanna try to use Elasticsearch in my education_  
_I'm using Node.JS_

JSON example:

> ```
> "companies" : 
> [{
> "title" : "value",
> "hash" : "UniqueValue",
> ...
> "employees" : [
> "position" : ["EmployeeName", "EmployeeName", "EmployeeName"],
> "position" : "EmployeeName",
> ...
> "position" : "EmployeeName"
> ],
> "key" : "value"
> }, and so on]
> 
> ```

More than 1000 different "position" exists. Every company have about 15 employees.

```
client.indices.create({
	index: "компании",
	body: {
		"mappings": {
			"companies": {
				"properties": {
					"title": {
						"type": "string"
					},
					"hash": {
						"type": "string"
					},
					...
					"employees": {
						???
					}
				}
			}
		}
	}
}, function (error, response) {
	var body = GetData();
	client.bulk({
		body: body
	}, function (err, resp) {
		res.render('index', {result: 'Indexing Completed!'});
	})
});

```

Questions:

1. How can i implement "employees"?
2. Since "hash" is unique - already existed values should be replaced with newest. Obviously i can just try to remove object with "hash" from database before add new information, but in my mind i'm not supposed to do that. There will be 5-10 removes every second and i think that this may potentially slow down the database in my case (since i'm just a student and don't have any big budgets for high-performance servers).

PS The main target is search - "employees". In 99% cases only they will be a criteria of query. Search may contain all 15 employees.

PPS What if i have much bigger object? Should i separate it or not? How?  
Example:

> ```
> "companies" : 
> [{
> "title" : "value",
> "hash" : "UniqueValue",
> ...
> "employees" : [
> "position" : ["EmployeeName", "EmployeeName", "EmployeeName"],
> "position" : "EmployeeName",
> "position" : ["key" : [values], "key" : ["key" : [values], "key" : ["key" : [values]]]], 
> ...
> "position" : "EmployeeName"
> ],
> "key" : "value"
> }, and so on]
> 
> ```

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [April 12, 2016, 8:20am UTC](https://discuss.elastic.co/t/how-can-i-create-this-indices/46928/2 "2016-04-12T08:20:06Z")

</div>

Hi,

you should have a read the [data modelling section of the Elasticsearch definitive guide](https://www.elastic.co/guide/en/elasticsearch/guide/master/modeling-your-data.html) and especially at parent-child. As you actually want to search for employees I think this should be a good fit.

Based on your example I'd create a "companies" index. Each company is one document in the index and has employees as child documents. The way you have modeled it now, you have just one huge document containing all documents.

Daniel

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:00pm UTC](https://discuss.elastic.co/t/how-can-i-create-this-indices/46928/3 "2017-07-05T23:00:21Z")

</div>

Closed on July 5, 2017, 11:00pm UTC


