# When to use Nested when to use has\_parent?

**URL:** <https://discuss.elastic.co/t/when-to-use-nested-when-to-use-has-parent/82792>\
**Category:** Elasticsearch\
**Created:** [April 18, 2017, 10:29pm UTC](https://discuss.elastic.co/t/when-to-use-nested-when-to-use-has-parent/82792 "2017-04-18T22:29:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshuaziering](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@joshuaziering](https://discuss.elastic.co/u/joshuaziering)\
**Post date:** [April 18, 2017, 10:29pm UTC](https://discuss.elastic.co/t/when-to-use-nested-when-to-use-has-parent/82792/1 "2017-04-18T22:29:56Z")

</div>

I'm working on a use case that I think Elasticsearch 5 would be great for but I'm still a little unsure on a couple of points.

I want to start telemetry records using Elasticsearch for search and aggregation operations.

Assumptions: 1) No record ever becomes "less valuable" than another. We won't be retiring any of this data, just adding to it.

1. The data is time-series data. I have been thinking of it like data frames. So, it's a collection of values associated to time. Here's a sample of one frame. An average set of these is easily 50,000. It's not uncommon in my use case to need all 50,000 frames at once, or at least a few values from them. (For example, if I want the path of the vehicle, I want all 50,000 lats and longs)

Questions:

Do I want to store each "frame" as it's own document? So for example:

"body" : [  
telemetry\_set\_id: 200,  
frame: {  
datetime: 2017-04-13 00:26:35,  
lat: "-37.0000",  
long: "127.000000",  
speed: "29.3",  
battery: "97%"  
}  
]

So this would mean to get the whole set of data I'd probably have to do a scroll operation for all documents that have telemetry\_set\_id:200.

It's an important use case for me to be able to make queries like, "Show me the highest speed for telemetry\_set 200" or "Show me all sets of telemetry data that include a coordinate within 5 miles of this X,Y coordinate. "

The other option is to make monstrous documents like this that contain an array of frame objects:

(Frames would be mapped to nested in this case)

"id" : "telemetry\_set\_200",  
"body" : [  
frames:[  
{

datetime: 2017-04-13 00:26:35,  
lat: "-37.0000",  
long: "127.000000",  
speed: "29.3",  
battery: "97%"  
},  
{  
datetime: 2017-04-13 00:26:36,  
lat: "-37.0030",  
long: "127.000010",  
speed: "30.1",  
battery: "96.5%"  
},  
{  
datetime: 2017-04-13 00:26:37,  
lat: "-37.0040",  
long: "127.000020",  
speed: "30.3",  
battery: "96%"  
}  
]  
]

The advantage here is that I can get the entire set of telemetry all at once which I feel is helpful. Will this still permit me to say, "Show me sets of telemetry data that include a lat/long within 5 miles of this specific lat and long?"

I could setup has\_parent as well. Is this more of a has\_parent problem or a "nested" data type problem? I think has\_parent is probably the answer here but I wouldn't mind hearing from some more seasoned professionals.

Thank you in advance, I'm excited to begin working with this new tool.

Josh

---

<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:** [May 16, 2017, 10:40pm UTC](https://discuss.elastic.co/t/when-to-use-nested-when-to-use-has-parent/82792/2 "2017-05-16T22:40:40Z")

</div>

Closed on May 16, 2017, 10:40pm UTC

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