# Determining 'size' in \[\_source \] \[includes\] query

**URL:** <https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451>\
**Category:** Elasticsearch\
**Created:** [August 25, 2021, 7:01am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451 "2021-08-25T07:01:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![clawrencia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clawrencia/32/93681_2.png) [@clawrencia](https://discuss.elastic.co/u/clawrencia)\
**Post date:** [August 25, 2021, 7:01am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/1 "2021-08-25T07:01:16Z")

</div>

Hi guys, I am just wondering if it possible to set the size for a particular field when we query.

The following here is my query. (Apologies for the mess, the query is done in the python elasticsearch API).

```auto
GET /index_name/_search
{

  "size": 10, 
  "query": {
      "bool": {
      "must": [],
      "filter": ["terms": {'employee_id.keyword': ['x'],
      "should": [],
      "must_not": []
    }
  },
    "_source": {"includes": ["employee_id","title_en","section_id","date_joined_at"]
    }
 "sort": [{"date_joined_at": {"order": "desc"}}
}

```

I want to have 'section\_id' in \_source limited to size 2. So the thing is section\_id returns a ton of ids (like around 100). I just want to return thefirst two values

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 25, 2021, 7:06am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/2 "2021-08-25T07:06:40Z")

</div>

Welcome to our community! 😃  
We aren't all guys though.

> [@clawrencia](#):
>
> if it possible to set the size for a particular field when we query

`size` is a query level thing.

What are you trying to achieve?

---

<div class="post-metadata">

**Author:** ![clawrencia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clawrencia/32/93681_2.png) [@clawrencia](https://discuss.elastic.co/u/clawrencia)\
**Post date:** [August 25, 2021, 7:21am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/3 "2021-08-25T07:21:15Z")

</div>

Hi Mark,

thanks for replying. I have cleaned up the code above and elaborated on what I really wanted.

So if you see the code:  
` "_source": {"includes": ["employee_id","title_en","section_id","date_joined_at"]`

section\_id here returns a lot of id (like around 100), when retrieving I want to limit this to just the first two ids. Is it possible to do so?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 25, 2021, 7:26am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/4 "2021-08-25T07:26:02Z")

</div>

So you want the first two `section_id` values, from the top 10 hits?

What sort of field is that `section_id`, is it an array?

---

<div class="post-metadata">

**Author:** ![clawrencia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clawrencia/32/93681_2.png) [@clawrencia](https://discuss.elastic.co/u/clawrencia)\
**Post date:** [August 25, 2021, 7:30am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/5 "2021-08-25T07:30:04Z")

</div>

Yep you are right.  
Yes it is an array.  
The image there is an example of what the return looks like. I just want the top 2

![image](https://us1.discourse-cdn.com/elastic/original/3X/a/0/a0fc9c227a41428b9534af8122a4c28db3dc37cc.png)

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 25, 2021, 7:31am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/6 "2021-08-25T07:31:12Z")

</div>

The issue here is that arrays in Elasticsearch (and in JSON more generally) are _not_ ordered at all. So the first two this time might be different next time, there's no guarantee.

---

<div class="post-metadata">

**Author:** ![clawrencia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clawrencia/32/93681_2.png) [@clawrencia](https://discuss.elastic.co/u/clawrencia)\
**Post date:** [August 25, 2021, 7:32am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/7 "2021-08-25T07:32:37Z")

</div>

Yeap no worries, I just want to cap it at 2. Since there are tons of ids it makes the search process slow

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 25, 2021, 7:35am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/8 "2021-08-25T07:35:31Z")

</div>

Ok, honestly I don't know of a way to do this sorry. Hopefully someone else can chime in with a suggestion.

---

<div class="post-metadata">

**Author:** ![clawrencia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clawrencia/32/93681_2.png) [@clawrencia](https://discuss.elastic.co/u/clawrencia)\
**Post date:** [August 25, 2021, 7:41am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/9 "2021-08-25T07:41:04Z")

</div>

Yeah it's very tricky 😔 I have tried all possible stuff before posting it here.  
But thank you very much for helping me

---

<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:** [September 22, 2021, 7:41am UTC](https://discuss.elastic.co/t/determining-size-in-source-includes-query/282451/10 "2021-09-22T07:41:56Z")

</div>

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