# Elasticsearch 'search' not returning all data

**URL:** <https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745>\
**Category:** Elasticsearch\
**Created:** [June 6, 2018, 7:19am UTC](https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745 "2018-06-06T07:19:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![roshni](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@roshni](https://discuss.elastic.co/u/roshni)\
**Post date:** [June 6, 2018, 7:19am UTC](https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745/1 "2018-06-06T07:19:09Z")

</div>

Hi ,

I have inserted some 1000 documents using a script  
`i=1 while [$i -le 998] do curl 'localhost:9200/test_index1/test_type1/'$i'' -d'{"name":"Hi , This is XYZ from location 10.0.4.135"}' i=`expr $i + 1`done`  
Prior to this I had created 1 shards with 0 replicas for this index  
curl -X PUT "localhost:9200/test\_index1" -H 'Content-Type: application/json' -d'  
{  
"settings" : {  
"index" : {  
"number\_of\_shards" : 1,  
"number\_of\_replicas" : 0  
}  
}  
}  
'

Now I am performing a simple search using  
curl -X GET "localhost:9200/test\_index1/\_search" -H 'Content-Type: application/json' -d'  
{  
"query": {  
"query\_string" : {  
"default\_field" : "name",  
"query" : "10.0.4.135"  
}  
}  
}  
'

It does not shows all the documents with the string 10.0.4.135 but only a few -  
{"took":1,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":549,"max\_score":0.59587663,"hits":[{"\_index":"test\_index1","\_type":"test\_type1","\_id":"521","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}},{"\_index":"test\_index1","\_type":"test\_type1","\_id":"522","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}},{"\_index":"test\_index1","\_type":"test\_type1","\_id":"523","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}},{"\_index":"test\_index1","\_type":"test\_type1","\_id":"524","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}},{"\_index":"test\_index1","\_type":"test\_type1","\_id":"525","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}},{"\_index":"test\_index1","\_type":"test\_type1","\_id":"526","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}},{"\_index":"test\_index1","\_type":"test\_type1","\_id":"527","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}},{"\_index":"test\_index1","\_type":"test\_type1","\_id":"528","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}},{"\_index":"test\_index1","\_type":"test\_type1","\_id":"529","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}},{"\_index":"test\_index1","\_type":"test\_type1","\_id":"530","\_score":0.59587663,"\_source":{"name":"Hi , This is XYZ from location 10.0.4.135"}}]}}Wed Jun 6 12:42:34 IST 2018

Can anyone please help me understand the same .

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [June 6, 2018, 7:54am UTC](https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745/2 "2018-06-06T07:54:13Z")

</div>

Does the loop work properly? Have you tried to decrease the number of iteration? lets say indexing just 10 documents?

---

<div class="post-metadata">

**Author:** ![roshni](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@roshni](https://discuss.elastic.co/u/roshni)\
**Post date:** [June 6, 2018, 8:48am UTC](https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745/3 "2018-06-06T08:48:59Z")

</div>

> [@roshni](#):
>
> curl -X GET "localhost:9200/test\_index1/\_search" -H 'Content-Type: application/json' -d'  
> {  
> "query": {  
> "query\_string" : {  
> "default\_field" : "name",  
> "query" : "10.0.4.135"  
> }  
> }  
> }  
> '

Hi , this works for 10 iterations,i.e. it is fetching all the 10 documents .. can you please explain its behavior for 1000 documents .

I have also tried with 100 iterations , it returns only 10 matches

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [June 6, 2018, 8:59am UTC](https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745/4 "2018-06-06T08:59:32Z")

</div>

All right, then your loop is working fine,  
so it would be good to have the responses returned by the curl requests...  
I don't know exactly what's wrong, so you need to gradually increase the number of iterations and check the behavior.  
Maybe add a sleep, to pause after each curl request?

---

<div class="post-metadata">

**Author:** ![roshni](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@roshni](https://discuss.elastic.co/u/roshni)\
**Post date:** [June 6, 2018, 9:20am UTC](https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745/5 "2018-06-06T09:20:20Z")

</div>

Hi ,

```
[root@node1 ~]# curl -X GET "localhost:9200/_cat/indices?v"

```

`health status index uuid pri rep docs.count docs.deleted store.size pri.store.size green open test_index1 gKOIJDmhSxuQGEqz3MGLcg 1 0 100 0 26.9kb 26.9kb`

This is showing doc.count = 100 but the result returned is only 1st 10 matching docs .  
This behavior is checked with doc.count=10, 20, 100, 500, 1000

Any leads would be highly appreciated .

Thanks

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [June 6, 2018, 9:29am UTC](https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745/6 "2018-06-06T09:29:43Z")

</div>

Sorry, are you aware that by default, ES returns the first 10 results? But the hits.total, will give you the total count.

Use the size parameter to fetch more documents.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html#search-request-from-size](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html#search-request-from-size)

---

<div class="post-metadata">

**Author:** ![roshni](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@roshni](https://discuss.elastic.co/u/roshni)\
**Post date:** [June 6, 2018, 10:51am UTC](https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745/7 "2018-06-06T10:51:08Z")

</div>

Thanks 🙂 that was much help

---

<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:** [July 4, 2018, 10:51am UTC](https://discuss.elastic.co/t/elasticsearch-search-not-returning-all-data/134745/8 "2018-07-04T10:51:13Z")

</div>

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