# resultsPerPage is not being sent in the query

**URL:** <https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [October 6, 2021, 5:28am UTC](https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976 "2021-10-06T05:28:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![reka.gay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reka.gay/32/91470_2.png) [@reka.gay](https://discuss.elastic.co/u/reka.gay)\
**Post date:** [October 6, 2021, 5:28am UTC](https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976/1 "2021-10-06T05:28:39Z")

</div>

I had to move the `SearchProvider` configuration to the server-side as we're using different engines based on the logged-in user's group. Given that I have to wrap practically the whole application in the `SearchProvider` (we have the search box in the header while the search page is rendered to look like an overlay) I added a wrapper around the provider: it returns just the children while the config is being fetched, then the children wrapped in the provider once we have the config:

```auto
import { SearchProvider } from "@elastic/react-search-ui";
export const SearchContext = (props) => {
    if (props.config) {
        return <SearchProvider config={props.config}>{props.children}</SearchProvider>
    }
    return <>{props.children}</> 
}

```

For some reason, this has caused 2 queries to be made rather than one - the second one without the `resultsPerPage` value in the query, so the query has (e.g. when using pagination to page 3):

**Query1**

```auto
"page":{"size":10,"current":3}

```

**Query2**

```auto
"page":{"size":0,"current":3}

```

This strangely means that results aren't being fetched after the initial first 100, so I can paginate up to 10 pages, but then I get no results back - so even though my search shows I have e.g. 500 results, I get an empty page on page 11.

Any ideas about why this might be happening??

---

<div class="post-metadata">

**Author:** ![anuragchoudhary01](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anuragchoudhary01/32/83611_2.png) [@anuragchoudhary01](https://discuss.elastic.co/u/anuragchoudhary01)\
**Post date:** [October 6, 2021, 5:44am UTC](https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976/2 "2021-10-06T05:44:44Z")

</div>

HI @reka.gay,  
Are you passing the initialState to the config( in your case props.config )?

"initialState": {  
"resultsPerPage": 10  
}

---

<div class="post-metadata">

**Author:** ![reka.gay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reka.gay/32/91470_2.png) [@reka.gay](https://discuss.elastic.co/u/reka.gay)\
**Post date:** [October 6, 2021, 7:30am UTC](https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976/3 "2021-10-06T07:30:14Z")

</div>

Hi @anuragchoudhary01 I tried with and without that setting, no change, unfortunately. I have it by default.

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [October 6, 2021, 12:37pm UTC](https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976/4 "2021-10-06T12:37:53Z")

</div>

Hey reka,

The conditional to load just children seems fine, I don't think that would cause any issues, but I don't know, I've never done anything like that before.

Are you sure that's what's causing two queries to be made instead of one? Search UI will often times make additional queries with "size: 0" to properly calculate facets, if you're using "disjunctive" facets.

And I have no idea why the paging is behaving that way, are you sure it's related?

Jason

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [October 6, 2021, 12:41pm UTC](https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976/5 "2021-10-06T12:41:15Z")

</div>

If you don't want to wrap your entire page in a `SearchProvider` you can create the "driver" separately and pass it into 2 separate instance of `SearchProvider`. That let's you use `SearchProvider` on the locations on your pages where you need it.

[search-ui/SearchProvider.js at master · elastic/search-ui · GitHub](https://github.com/elastic/search-ui/blob/master/packages/react-search-ui/src/SearchProvider.js#L13). It accepts a param called "driver".

You instantiate with the same configuration that you would use for the provider.

> **[search-ui/packages/search-ui at master · elastic/search-ui - Usage](https://github.com/elastic/search-ui/tree/master/packages/search-ui#usage)**
>
> master/packages/search-ui

---

<div class="post-metadata">

**Author:** ![reka.gay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reka.gay/32/91470_2.png) [@reka.gay](https://discuss.elastic.co/u/reka.gay)\
**Post date:** [October 6, 2021, 12:41pm UTC](https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976/6 "2021-10-06T12:41:48Z")

</div>

I'm not convinced but I reverted all my changes yesterday and served the config locally again, everything was working fine. It is very odd.

I even tried defining an `onSearch` in the config to make absolutely sure that `resultsPerPage` gets included to no avail.

It is entirely possible that I haven't found the root cause yet but it definitely felt like I was on the right track with this last night.

---

<div class="post-metadata">

**Author:** ![reka.gay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reka.gay/32/91470_2.png) [@reka.gay](https://discuss.elastic.co/u/reka.gay)\
**Post date:** [October 6, 2021, 12:43pm UTC](https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976/7 "2021-10-06T12:43:05Z")

</div>

Oh, that sounds very useful, I'll definitely have a look later!!

---

<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:** [November 3, 2021, 12:43pm UTC](https://discuss.elastic.co/t/resultsperpage-is-not-being-sent-in-the-query/285976/8 "2021-11-03T12:43:46Z")

</div>

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