Sorting Second Search Based on Sort of First Search (Sorting Path Feature)

Hi Elasticsearchers,

I was wondering if anyone encountered the issue above and what their
experience was.

Basically, say you have two related searches for two types of
documents. Perhaps, the documents are sharded using the new routing
feature based on a document field value of the first search. Assume
that both documents have date fields. But, you want to sort the first
search based on the date field values of the first type of document.
And you will display the second search results side by side with the
first search results. But, to maintain some order, you want to sort
the second search results based on the date field values of the first
type of documents. Otherwise, you may have search results displayed
side by side that are not related.

In other words, is there a sorting path akin to routing path in
Elasticsearch? Or does this have to be done externally?

Cheers,
Ted

Not sure I followed exactly what you are after. Are those two different
search queries, but both sorted by date? How does the first query affect the
second query?

On Fri, Nov 26, 2010 at 4:15 PM, Ted Karmel ted.karmel@gmail.com wrote:

Hi Elasticsearchers,

I was wondering if anyone encountered the issue above and what their
experience was.

Basically, say you have two related searches for two types of
documents. Perhaps, the documents are sharded using the new routing
feature based on a document field value of the first search. Assume
that both documents have date fields. But, you want to sort the first
search based on the date field values of the first type of document.
And you will display the second search results side by side with the
first search results. But, to maintain some order, you want to sort
the second search results based on the date field values of the first
type of documents. Otherwise, you may have search results displayed
side by side that are not related.

In other words, is there a sorting path akin to routing path in
Elasticsearch? Or does this have to be done externally?

Cheers,
Ted

Yes, they are two different queries on two different document types.
The documents share a field. But you do not want to sort based on
that field. You want to sort based on the date field of the first
search.

A more concrete example may perhaps make what I'm trying to say more
clear. Say you have one document which basically represents an image:
{ imagename: joe, imageurl: /pictures/joe.jpg, creationdate:
2010-11-20T13:12:09 }. And you have a document which represents the
number of times the image has been viewed: { imagename: joe,
imageviews: 26, lastviewed: 20010-11-26T10:21:34 }.

You need to display the documents side by side - the image name and
url along with the total number of views. You have multiple documents
and you choose to sort by the creationdate instead of name. Needless
to say, if both documents were sorted by the shared field of imagename
we wouldn't be discussing this.

So the issue is how do you ensure that the results from the query on
the second document of image views is ordered in the same way as the
results from the query on the first document?

I hope this is clear. Apologies if it isn't. Let me know and I will
try to explain myself better.

On Fri, Nov 26, 2010 at 8:33 PM, Shay Banon
shay.banon@elasticsearch.com wrote:

Not sure I followed exactly what you are after. Are those two different
search queries, but both sorted by date? How does the first query affect the
second query?

On Fri, Nov 26, 2010 at 4:15 PM, Ted Karmel ted.karmel@gmail.com wrote:

Hi Elasticsearchers,

I was wondering if anyone encountered the issue above and what their
experience was.

Basically, say you have two related searches for two types of
documents. Perhaps, the documents are sharded using the new routing
feature based on a document field value of the first search. Assume
that both documents have date fields. But, you want to sort the first
search based on the date field values of the first type of document.
And you will display the second search results side by side with the
first search results. But, to maintain some order, you want to sort
the second search results based on the date field values of the first
type of documents. Otherwise, you may have search results displayed
side by side that are not related.

In other words, is there a sorting path akin to routing path in
Elasticsearch? Or does this have to be done externally?

Cheers,
Ted

I think I got it now. No, there isn't a mechanism to do it out of the box in
ES, so you will have to do it on the client side. I have some ideas on how
to solve this, but it still need to be implemented :wink:

On Sat, Nov 27, 2010 at 11:00 PM, Ted Karmel ted.karmel@gmail.com wrote:

Yes, they are two different queries on two different document types.
The documents share a field. But you do not want to sort based on
that field. You want to sort based on the date field of the first
search.

A more concrete example may perhaps make what I'm trying to say more
clear. Say you have one document which basically represents an image:
{ imagename: joe, imageurl: /pictures/joe.jpg, creationdate:
2010-11-20T13:12:09 }. And you have a document which represents the
number of times the image has been viewed: { imagename: joe,
imageviews: 26, lastviewed: 20010-11-26T10:21:34 }.

You need to display the documents side by side - the image name and
url along with the total number of views. You have multiple documents
and you choose to sort by the creationdate instead of name. Needless
to say, if both documents were sorted by the shared field of imagename
we wouldn't be discussing this.

So the issue is how do you ensure that the results from the query on
the second document of image views is ordered in the same way as the
results from the query on the first document?

I hope this is clear. Apologies if it isn't. Let me know and I will
try to explain myself better.

On Fri, Nov 26, 2010 at 8:33 PM, Shay Banon
shay.banon@elasticsearch.com wrote:

Not sure I followed exactly what you are after. Are those two different
search queries, but both sorted by date? How does the first query affect
the
second query?

On Fri, Nov 26, 2010 at 4:15 PM, Ted Karmel ted.karmel@gmail.com
wrote:

Hi Elasticsearchers,

I was wondering if anyone encountered the issue above and what their
experience was.

Basically, say you have two related searches for two types of
documents. Perhaps, the documents are sharded using the new routing
feature based on a document field value of the first search. Assume
that both documents have date fields. But, you want to sort the first
search based on the date field values of the first type of document.
And you will display the second search results side by side with the
first search results. But, to maintain some order, you want to sort
the second search results based on the date field values of the first
type of documents. Otherwise, you may have search results displayed
side by side that are not related.

In other words, is there a sorting path akin to routing path in
Elasticsearch? Or does this have to be done externally?

Cheers,
Ted

Ok thanks Shay... Appreciated anyway.

On Sat, Nov 27, 2010 at 9:07 PM, Shay Banon
shay.banon@elasticsearch.com wrote:

I think I got it now. No, there isn't a mechanism to do it out of the box in
ES, so you will have to do it on the client side. I have some ideas on how
to solve this, but it still need to be implemented :wink:

On Sat, Nov 27, 2010 at 11:00 PM, Ted Karmel ted.karmel@gmail.com wrote:

Yes, they are two different queries on two different document types.
The documents share a field. But you do not want to sort based on
that field. You want to sort based on the date field of the first
search.

A more concrete example may perhaps make what I'm trying to say more
clear. Say you have one document which basically represents an image:
{ imagename: joe, imageurl: /pictures/joe.jpg, creationdate:
2010-11-20T13:12:09 }. And you have a document which represents the
number of times the image has been viewed: { imagename: joe,
imageviews: 26, lastviewed: 20010-11-26T10:21:34 }.

You need to display the documents side by side - the image name and
url along with the total number of views. You have multiple documents
and you choose to sort by the creationdate instead of name. Needless
to say, if both documents were sorted by the shared field of imagename
we wouldn't be discussing this.

So the issue is how do you ensure that the results from the query on
the second document of image views is ordered in the same way as the
results from the query on the first document?

I hope this is clear. Apologies if it isn't. Let me know and I will
try to explain myself better.

On Fri, Nov 26, 2010 at 8:33 PM, Shay Banon
shay.banon@elasticsearch.com wrote:

Not sure I followed exactly what you are after. Are those two different
search queries, but both sorted by date? How does the first query affect
the
second query?

On Fri, Nov 26, 2010 at 4:15 PM, Ted Karmel ted.karmel@gmail.com
wrote:

Hi Elasticsearchers,

I was wondering if anyone encountered the issue above and what their
experience was.

Basically, say you have two related searches for two types of
documents. Perhaps, the documents are sharded using the new routing
feature based on a document field value of the first search. Assume
that both documents have date fields. But, you want to sort the first
search based on the date field values of the first type of document.
And you will display the second search results side by side with the
first search results. But, to maintain some order, you want to sort
the second search results based on the date field values of the first
type of documents. Otherwise, you may have search results displayed
side by side that are not related.

In other words, is there a sorting path akin to routing path in
Elasticsearch? Or does this have to be done externally?

Cheers,
Ted