Sorting multiple indices with different fields

Hi there,

I'm having a sorting issue.
I have 2 indexes which I search.
I want to sort on a date field, but they have different names in each index:
index01 has a datefield: publishedDate
index02 has a datefield: postedDate

I fire this query:

GET index01,index02/_search
{
  "sort":[
         {
            "publishedDate":{
               "order":"desc",
               "unmapped_type":"date"
            }
         },
         {
            "postedDate":{
               "order":"desc",
               "unmapped_type":"date"
            }
         }
      ]
}

I'm getting my results as follows:
1st all hits from index01, ordered by publishedDate
2nd all hits from index02, ordered by postedDate

What I would like to get however is all results ordered by date, regardless of the index they're in.

Is this possible?

Best Regards,

Marten

Hi Marten.

Maybe you must use multi search API

This way you can send several searches in one request. You can create a query on criterion A and another on criterion B

Hi RabBit,

Thanks for your response.
My problem isn't the query, it's the sorting.
I want all hits sorted on a date, but the name of the datefield is diferent in my indexes.
I've solved it now by copying the datefield to another field with the same name in all indices, but I think this should be possible in another way.

Best Regards,

Marten

I'm experiencing a similar problem.
In my case the indexes are different, and in some searches I only have the docs of just one index at the top. This is because the classification in each index is different due to the frequency of documents.
Then I thought of using msearch because I can separate queries and sorting.
As in your case the indices are the same so it's not like my problem.

Hmm, I thought that it's impossible to sort on the combined results of a msearch.
Did you manage to solve your problem?

I'm still thinking about which strategy to use, but the results with msearch are nice

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