# Help with nested datatype or parent/child documents

**URL:** <https://discuss.elastic.co/t/help-with-nested-datatype-or-parent-child-documents/109658>\
**Category:** Elasticsearch\
**Created:** [November 29, 2017, 11:03pm UTC](https://discuss.elastic.co/t/help-with-nested-datatype-or-parent-child-documents/109658 "2017-11-29T23:03:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petar\_Pavlovic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/petar_pavlovic/32/465_2.png) [@Petar\_Pavlovic](https://discuss.elastic.co/u/Petar_Pavlovic)\
**Post date:** [November 29, 2017, 11:03pm UTC](https://discuss.elastic.co/t/help-with-nested-datatype-or-parent-child-documents/109658/1 "2017-11-29T23:03:22Z")

</div>

I'm having a problem with organizing index, so I would appreciate your help.

My data is like this:

```
make model bodystyle trim package price
Audi A3 hatchback 1.6TDI Package1 18000
Audi A3 hatchback 2.0TDI Package2 22000
Audi A3 hatchback 3.0TSI Package1 26000
Audi A4 sedan 2.0TDI Package1 30000
Audi A4 sedan 3.0TDI Package1 36000
BMW 3 Series sedan 320i Package1 33000
BMW 3 Series sedan 330i Package1 40000
BMW 5 Series sedan 520d Package1 38000
BMW 5 Series sedan 530d Package1 45000

```

I need to do a query for example `package.price gte 15000` to have results like this (only show lowest price):

```
make model price
Audi A3 18000
Audi A4 30000
BMW 3 Series 33000
BMW 5 Series 38000

```

For query `package.price gte 25000` this should be the result:

```
make model price
Audi A3 26000 <--
Audi A4 30000
BMW 3 Series 33000
BMW 5 Series 38000

```

Also, I need to sort results by make and price, asc or desc.

My first try is to make parent-child relation

```
PUT /baza2
{
  "mappings": {
    "make_model": {},
    "trim": {
      "_parent": {
        "type": "make_model"
      }
    },
    "package": {
      "_parent": {
        "type": "trim"
      }
    }
  }
}

```

When I query for package.price, I get results as I want, but one problem: **I don't see price from nested document. How can I "pull" price to parent document?**  
I also have problem with sorting results by price.

I've tried with nested types, but I get duplicate results like:

```
Audi A3 18000
Audi A3 22000
Audi A3 26000
Audi A4 30000
Audi A4 36000

```

If I "search" using aggregates, then I loose number of results, pagination, etc ...

Am I missing something ?

---

<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:** [December 27, 2017, 11:03pm UTC](https://discuss.elastic.co/t/help-with-nested-datatype-or-parent-child-documents/109658/2 "2017-12-27T23:03:24Z")

</div>

Closed on December 27, 2017, 11:03pm UTC

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