Difference on sorting between query_and_fetch and query_then_fetch


(alheim) #1

Hi,

I try to get a list of documents ordered by a field. No specific limit or
offset used. Just a search with a sort.

The returned documents are just sorted "by shards". In other words, the
first 3 documents are sorted right, then the 4th is not well sorted but the
10 following are well sorted comparing to the 4th...

I understand that each shard returns a sorted result set. Right ?

But I thought that the search_type could change this behavior and apply the
sort after having fetched documents.

Please explain to me, thanks


(Shay Banon) #2

You get proper sorted results when you use query_then_fetch (across all top
"size" results), if you use query_and_fetch, then each shard return the size
requested hits, and then they are sorted between them.

On Thu, Oct 6, 2011 at 11:27 AM, Alexandre Heimburger <
ahb@bluekiwi-software.com> wrote:

Hi,

I try to get a list of documents ordered by a field. No specific limit or
offset used. Just a search with a sort.

The returned documents are just sorted "by shards". In other words, the
first 3 documents are sorted right, then the 4th is not well sorted but the
10 following are well sorted comparing to the 4th...

I understand that each shard returns a sorted result set. Right ?

But I thought that the search_type could change this behavior and apply the
sort after having fetched documents.

Please explain to me, thanks


(alheim) #3

Hi Kimchy,

My issue is related to nested fields (again sorry). I got this strange
behavior each time a use a sort pattern like "path1.path2.sortedField".
Everything is working fine when sorting fields are attached directly to the
root document.

Any idea ?


(alheim) #4

Forget my last comment please...It's monday morning. I wanted to index
integer but the field was indexed as a string...
Thanks again for your help (and your patience).


(system) #5