# Inconsistent results (Preference = Custom (string) UserId)

**URL:** <https://discuss.elastic.co/t/inconsistent-results-preference-custom-string-userid/22823>\
**Category:** Elasticsearch\
**Created:** [March 23, 2015, 1:40pm UTC](https://discuss.elastic.co/t/inconsistent-results-preference-custom-string-userid/22823 "2015-03-23T13:40:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andavar](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andavar](https://discuss.elastic.co/u/andavar)\
**Post date:** [March 23, 2015, 1:40pm UTC](https://discuss.elastic.co/t/inconsistent-results-preference-custom-string-userid/22823/1 "2015-03-23T13:40:37Z")

</div>

Hi Elastic Users,  
We have 6 shards 2 replicas(3 nodes). While am searching in node1 it gave one result, then pass the query to node2 & 3 it gave different order.

I tried preference = \_primary & \_primary\_first It will returns correct order in all the nodes.

But I tried preference = userId(003fdaa6-c5e7-4578-a70e-1c010d358960). This will also returns the first results(Inconsistent results).

Could you please help me how to resolve the issue.

---

<div class="post-metadata">

**Author:** ![andavar](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andavar](https://discuss.elastic.co/u/andavar)\
**Post date:** [March 27, 2015, 11:15am UTC](https://discuss.elastic.co/t/inconsistent-results-preference-custom-string-userid/22823/2 "2015-03-27T11:15:37Z")

</div>

Hi All  
Plz give suggestion for this post. Any configuration need to be change in my yml file.  
Note: I did not changed anything in yml file. Am using elastic1.3.1

---

<div class="post-metadata">

**Author:** ![masaru](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@masaru](https://discuss.elastic.co/u/masaru)\
**Post date:** [March 30, 2015, 5:53am UTC](https://discuss.elastic.co/t/inconsistent-results-preference-custom-string-userid/22823/3 "2015-03-30T05:53:28Z")

</div>

Hi,

Is the number of hits the same every time? And are those documents have the same score?  
If so, the behavior is expected. Elasticsearch (Lucene) uses Lucene's internal document ID when score is the same.  
You can supply secondary sort criterion like "\_uid" to make order consistent.

Masaru  
On March 27, 2015 at 20:15:43, andavar ([andavar\_laxman@rediffmail.com](mailto:andavar_laxman@rediffmail.com)) wrote:

Hi All  
Plz give suggestion for this post. Any configuration need to be change in  
my yml file.  
Note: I did not changed in anything in yml file. Am using elastic1.3.1

--  
View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Inconsistent-results-Preference-Custom-string-UserId-tp4072415p4072704.html](http://elasticsearch-users.115913.n3.nabble.com/Inconsistent-results-Preference-Custom-string-UserId-tp4072415p4072704.html)  
Sent from the ElasticSearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1427454937397-4072704.post%40n3.nabble.com](https://groups.google.com/d/msgid/elasticsearch/1427454937397-4072704.post%40n3.nabble.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.5518e515.66ef438d.166%40citra-2.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5518e515.66ef438d.166%40citra-2.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![andavar](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andavar](https://discuss.elastic.co/u/andavar)\
**Post date:** [March 30, 2015, 8:18am UTC](https://discuss.elastic.co/t/inconsistent-results-preference-custom-string-userid/22823/4 "2015-03-30T08:18:14Z")

</div>

Thanks for reply Masaru.

> > > Is the number of hits the same every time?  
> > > **yes**  
> > > And are those documents have the same score?  
> > > **no** node by node it have different score  
> > > If I will try preference= \_primary & \_primary\_first same score in all nodes.

> **[Preference | Elasticsearch Guide \[1.3\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/1.3/search-request-preference.html)**

But the above link told same shards hits while preference = sessionId or userId  
I think this only not happen.

Plz suggest any settings need to be change.

---

<div class="post-metadata">

**Author:** ![masaru](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@masaru](https://discuss.elastic.co/u/masaru)\
**Post date:** [March 31, 2015, 1:36am UTC](https://discuss.elastic.co/t/inconsistent-results-preference-custom-string-userid/22823/5 "2015-03-31T01:36:10Z")

</div>

_no_ node by node it have different score

In that case, difference in score may be due to shard(or segment) state in each node (some shard still have deleted document in segments and others not).  
It's noticeable when number of documents is relatively small.

If you'd like consistent result, you can use preference parameter. As long as you use the same preference, queries should hit the same set of shards.  
Are you saying preference doesn't work like that?  
If you add "explain":true to the query, you'll see which node and shard each document comes from.

Masaru  
On March 30, 2015 at 17:18:22, andavar ([andavar\_laxman@rediffmail.com](mailto:andavar_laxman@rediffmail.com)) wrote:

Thanks for reply Masaru.

> > > Is the number of hits the same every time?  
> > > _yes_  
> > > And are those documents have the same score?  
> > > _no_ node by node it have different score  
> > > If I will try preference= \_primary & \_primary\_first same score in all  
> > > nodes.

> **[Preference | Elasticsearch Guide \[1.3\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/1.3/search-request-preference.html)**

But the above link told same shards hits while preference = sessionId or  
userId  
I think this only not happen.

Plz suggest any settings need to be change.

--  
View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Inconsistent-results-Preference-Custom-string-UserId-tp4072415p4072816.html](http://elasticsearch-users.115913.n3.nabble.com/Inconsistent-results-Preference-Custom-string-UserId-tp4072415p4072816.html)  
Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1427703494305-4072816.post%40n3.nabble.com](https://groups.google.com/d/msgid/elasticsearch/1427703494305-4072816.post%40n3.nabble.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.551a02f6.643c9869.3b55%40citra-2.local](https://groups.google.com/d/msgid/elasticsearch/etPan.551a02f6.643c9869.3b55%40citra-2.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:22am UTC](https://discuss.elastic.co/t/inconsistent-results-preference-custom-string-userid/22823/6 "2017-07-06T00:22:59Z")

</div>


