# How are the requestQueue populated in the source code?

**URL:** <https://discuss.elastic.co/t/how-are-the-requestqueue-populated-in-the-source-code/114189>\
**Category:** Kibana\
**Created:** [January 5, 2018, 1:18am UTC](https://discuss.elastic.co/t/how-are-the-requestqueue-populated-in-the-source-code/114189 "2018-01-05T01:18:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joey\_Andres](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joey_andres/32/44982_2.png) [@Joey\_Andres](https://discuss.elastic.co/u/Joey_Andres)\
**Post date:** [January 5, 2018, 1:18am UTC](https://discuss.elastic.co/t/how-are-the-requestqueue-populated-in-the-source-code/114189/1 "2018-01-05T01:18:47Z")

</div>

Hello,

Currently, at least in Discover page, when you make a query while there is a current msearch going on, the msearch is only done for the very first query. Subsequent changes don't receive any msearch. This can be confirmed by tracking the msearch requests in your browser's development tools. I have posted a bug report about this in [https://github.com/elastic/kibana/issues/15840](https://github.com/elastic/kibana/issues/15840).

I was tasked to modify (if this is the expected behaviour) or fix this. I've been looking around courier.js's fetch() function and I ended up looking at requestQueue in that gets populated when a Request object is initialized. More specifically SegmentedReq in SegmentedRequestProvider. I mentioned that since courier.fetch() fetches things that are in the requestQueue.

My problem now is when are requestQueue populated. discover.js's fetch() don't seem to do a thing in terms of populating the queue, it assumes that it is already populated by then. I also don't know who calls the callback returned by onBeginSegmentedFetch, which if called, populates the requestQueue.

Any help would be appreciated,  
Cheers.

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [January 8, 2018, 4:49pm UTC](https://discuss.elastic.co/t/how-are-the-requestqueue-populated-in-the-source-code/114189/2 "2018-01-08T16:49:56Z")

</div>

Hi @Joey_Andres,

you're not facing an easy task there. 😉 But joking aside, it the `SearchRequests` [add themselves to the queue](https://github.com/elastic/kibana/blob/51c005cf3a9c86f3dd2c5c8459e9f47cd975b3c9/src/ui/public/courier/fetch/request/search_request.js#L14). As far as I understand, the request is created in the [`onBeginSegmentedFetch` method](https://github.com/elastic/kibana/blob/51c005cf3a9c86f3dd2c5c8459e9f47cd975b3c9/src/ui/public/courier/data_source/search_source.js#L177), which is [called from the discover controller](https://github.com/elastic/kibana/blob/51c005cf3a9c86f3dd2c5c8459e9f47cd975b3c9/src/core_plugins/kibana/public/discover/controllers/discover.js#L572).

---

<div class="post-metadata">

**Author:** ![Joey\_Andres](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joey_andres/32/44982_2.png) [@Joey\_Andres](https://discuss.elastic.co/u/Joey_Andres)\
**Post date:** [January 8, 2018, 5:27pm UTC](https://discuss.elastic.co/t/how-are-the-requestqueue-populated-in-the-source-code/114189/3 "2018-01-08T17:27:21Z")

</div>

Hello @weltenwort

I figured it out. I made a pull request at [https://github.com/elastic/kibana/pull/15873](https://github.com/elastic/kibana/pull/15873). The fix should not interfere with other modules. It should only be at Discover page. I'm gonna integrate this to our instance. I'll gladly work with you folks to improve this commit.

Cheers.

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [January 15, 2018, 3:10pm UTC](https://discuss.elastic.co/t/how-are-the-requestqueue-populated-in-the-source-code/114189/4 "2018-01-15T15:10:40Z")

</div>

Awesome, thanks a lot! :elasticheart:

---

<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:** [February 12, 2018, 3:10pm UTC](https://discuss.elastic.co/t/how-are-the-requestqueue-populated-in-the-source-code/114189/5 "2018-02-12T15:10:55Z")

</div>

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