# Is it even possible?

**URL:** <https://discuss.elastic.co/t/is-it-even-possible/65855>\
**Category:** Elasticsearch\
**Created:** [November 12, 2016, 12:17am UTC](https://discuss.elastic.co/t/is-it-even-possible/65855 "2016-11-12T00:17:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pungent](https://avatars.discourse-cdn.com/v4/letter/p/a698b9/32.png) [@pungent](https://discuss.elastic.co/u/pungent)\
**Post date:** [November 12, 2016, 12:17am UTC](https://discuss.elastic.co/t/is-it-even-possible/65855/1 "2016-11-12T00:17:58Z")

</div>

Let's take an example and then I will explain what am I trying to solve.

Suppose my mapping is as follows:

```
{
  "parent_id": { "type": "integer" },   
  "mydata": {
    "type": "nested",
    "dynamic": "strict",
    "properties": {
      "name": {"type": "string"},
      "location": { "type": "geo_point"} 
    }                     
  }

```

}

Here I want to find all documents (in pagination way = 10 docs per page) matching some criteria, but in that result set, I want to keep ONLY one best match the highest scored) document with unique `parent_id`. That means suppose in the result, there are five such documents which have same `parent_id`, then I will pick one of those based on the highest score among them. However, in the end, the pagination should ALWAYS return me the desired (say 10) numbers of the result after the elimination. Is it even possible to do at the query time? I am using ES 2.3

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 12, 2016, 9:42pm UTC](https://discuss.elastic.co/t/is-it-even-possible/65855/2 "2016-11-12T21:42:35Z")

</div>

Try using inner hits with your nested query:  
[https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-inner-hits.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-inner-hits.html)

Ivan

---

<div class="post-metadata">

**Author:** ![pungent](https://avatars.discourse-cdn.com/v4/letter/p/a698b9/32.png) [@pungent](https://discuss.elastic.co/u/pungent)\
**Post date:** [November 13, 2016, 12:13am UTC](https://discuss.elastic.co/t/is-it-even-possible/65855/3 "2016-11-13T00:13:30Z")

</div>

How `inner_hits` gonna solve this problem?

---

<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 11, 2016, 12:13am UTC](https://discuss.elastic.co/t/is-it-even-possible/65855/4 "2016-12-11T00:13:43Z")

</div>

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