# Search API doesn't return consistent results. First query returns 2 hits, second in 3 hits, third 2 hits and so on

**URL:** https://discuss.elastic.co/t/search-api-doesnt-return-consistent-results-first-query-returns-2-hits-second-in-3-hits-third-2-hits-and-so-on/10540
**Category:** Elasticsearch
**Created:** [January 29, 2013, 3:58pm UTC](https://discuss.elastic.co/t/search-api-doesnt-return-consistent-results-first-query-returns-2-hits-second-in-3-hits-third-2-hits-and-so-on/10540 "2013-01-29T15:58:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Olav\_Gronas\_Gjerde](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@Olav\_Gronas\_Gjerde](https://discuss.elastic.co/u/Olav_Gronas_Gjerde)
#### Post date: [January 29, 2013, 3:58pm UTC](https://discuss.elastic.co/t/search-api-doesnt-return-consistent-results-first-query-returns-2-hits-second-in-3-hits-third-2-hits-and-so-on/10540/1 "2013-01-29T15:58:31Z")

</div>

Example

curl -XGET '[http://localhost:9200/testolav/node/\_search](http://localhost:9200/testolav/node/_search)' -d'  
{  
"from": 0,  
"size": 0,  
"fields": [],  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"parent": "%2Ftestolav"  
}  
}  
]  
}  
}  
}'  
{"took":2,"timed\_out":false,"\_shards":{"total":2,"successful":2,"failed":0},"hits":{"total":2,"max\_score":3.014903,"hits":[]}}

\_index  
\_type  
\_id  
\_score  
size  
type  
name  
parent  
date\_modified  
testolav  
node  
%2Ftestolav%2F%E2%80%93  
3.014903  
0 bytes  
file  
–  
%2Ftestolav  
2013-01-29 16:07  
testolav  
node  
%2Ftestolav%2Ftruls  
3.014903

FOLDER  
truls  
%2Ftestolav  
2013-01-29 16:10

Second query:  
curl -XGET '[http://localhost:9200/testolav/node/\_search](http://localhost:9200/testolav/node/_search)' -d'  
{  
"from": 0,  
"size": 0,  
"fields": [],  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"parent": "%2Ftestolav"  
}  
}  
]  
}  
}  
}'  
{"took":3,"timed\_out":false,"\_shards":{"total":2,"successful":2,"failed":0},"hits":{"total":3,"max\_score":3.74084,"hits":[]}}

\_index  
\_type  
\_id  
\_score  
size  
type  
name  
parent  
date\_modified  
testolav  
node  
%2Ftestolav%2FMusic  
3.74084

folder  
Music  
%2Ftestolav  
2013-01-21 13:50  
testolav  
node  
%2Ftestolav%2F%E2%80%93  
3.014903  
0 bytes  
file  
–  
%2Ftestolav  
2013-01-29 16:07  
testolav  
node  
%2Ftestolav%2Ftruls  
3.014903

FOLDER  
truls  
%2Ftestolav  
2013-01-29 16:10

Is this supposed to happen? Is there a way to return a consistent search  
result?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Olav\_Gronas\_Gjerde](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@Olav\_Gronas\_Gjerde](https://discuss.elastic.co/u/Olav_Gronas_Gjerde)
#### Post date: [January 29, 2013, 4:21pm UTC](https://discuss.elastic.co/t/search-api-doesnt-return-consistent-results-first-query-returns-2-hits-second-in-3-hits-third-2-hits-and-so-on/10540/2 "2013-01-29T16:21:51Z")

</div>

I changed the index mapping on the name property from

'name': { 'type': 'string', 'index': 'analyzed' } to 'name': { 'type':  
'string', 'index': 'not\_analyzed' }

And now the returned documents are always consistent.  
But isn't it better to have the name field analyzed if you want it to be  
searchable?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [January 30, 2013, 9:37am UTC](https://discuss.elastic.co/t/search-api-doesnt-return-consistent-results-first-query-returns-2-hits-second-in-3-hits-third-2-hits-and-so-on/10540/3 "2013-01-30T09:37:58Z")

</div>

On Tue, 2013-01-29 at 08:21 -0800, Olav Grønås Gjerde wrote:

> I changed the index mapping on the name property from
> 
> 'name': { 'type': 'string', 'index': 'analyzed' } to 'name':  
> { 'type': 'string', 'index': 'not\_analyzed' }

> And now the returned documents are always consistent.

I think that this was coincidental. I think the real issue was that  
somehow you managed to end up with more docs on the primaries than on  
the replicas. So when you changed the mapping (ie reindexed) then it  
sorted out the doc inconsistency.

I don't know how you ended up with replicas being different from  
primaries. Did you have any OOM or other errors while indexing?.

> But isn't it better to have the name field analyzed if you want it to  
> be searchable?

that depends what the name field represents in your data. A not\_analyzed  
field is still searchable, but eg if your name is "John Smith" and it is  
analyzed, then you can search on "john". If it is not\_analyzed then you  
can only search on the exact value "John Smith".

clint

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:54am UTC](https://discuss.elastic.co/t/search-api-doesnt-return-consistent-results-first-query-returns-2-hits-second-in-3-hits-third-2-hits-and-so-on/10540/4 "2017-07-06T02:54:01Z")

</div>


