Need to return *all* the results from a search using ReactJS

I am helping another developer with a ReactJS search application. No matter what I've tried, the search always returns exactly ten results. We need to return all the results of the search.

I have added from:0 and size:1000 to the query, two different ways. I'll include the code below. How can I return all the results, not just the default 10?

This is part of a file called search.js:
const { client, index } = require('./connection')
async function queryTerm (term, datasets){ //this is called from index.js
const body = {
"_source": {
"includes":[ "field1", "field2", "field3"]
"query": term
return await{
index: datasets,
body: body

The connection.js file looks like this:
const { Client } = require('@elastic/elasticsearch')
const es_host = process.env.ES_HOST
const index=
const client = new Client({ node: es_host })
async function testConnection () {
try {
const response = await{requstTimeout:1000})
} catch (e) {
console.trace('elasticsearch cluster is down');
module.exports = {

The index.js component that uses the search component above, looks like this (this is the beginning of this component, the relevant part):
const express = require('express')
const app = express()
const { serverStatusHtml } = require('./constants')
const cors = require('cors')
const search = require('./search')
const port = process.env.PORT || 3001
app.get('/status',(req,res) = > res.send('${serverStatusHtml}'))'/search', async (req, res) => {
const (query, datasets } = req.body;
let {term} = req.body;
if(query) term = query;
if(term.trim()=="*") res.status(400).send('Invalid search...');
try {
const result = await search.queryTerm(term,datasets) //this is where search.js is called
if(result && result.meta) delete result.meta;
if(result && result.body && result.body._shards) delete result.body._shards;
} catch (e) {
res.status(400).send('Search failed...')

Then there is another component called demo.js that displays the results in a table. It's too long to type here. But I will say that we are using getInitialProps, which always seems to return 10 results only. Do you see anything above that would prevent the search from returning all the results???


I'm not expert at ReactJS, but maybe i can be of some help.
How many documents have the Index you are consulting? Have you tried using the scroll api to search the index?

Is there any response that the cluster is giving to you? The count field of the JSON response is 10 too?


Hi John. I have a small test index of 12 documents. I have searched the index with Kibana, and see all 12 documents. And after a search, I can look at the web console in the browser and see that the is 12. BUT for some odd reason, the data.body.hits.hits Array only displays 10 results. I need to find out how to capture the total value, and how to expand the Array to include all the results.

So, I got some of it working. We're using PM2 to manage the web servers, one for front end, one for back end. After making the FILE and SIZE changes, I had to restart the back end PM2 "server" and now the FILE and SIZE properties are behaving as expected. I do need to paginate these, though, so that's my next challenge!

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