# Sorting multiple indices with different fields

**URL:** <https://discuss.elastic.co/t/sorting-multiple-indices-with-different-fields/301315>\
**Category:** Elasticsearch\
**Created:** [April 1, 2022, 11:00am UTC](https://discuss.elastic.co/t/sorting-multiple-indices-with-different-fields/301315 "2022-04-01T11:00:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![marten1](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@marten1](https://discuss.elastic.co/u/marten1)\
**Post date:** [April 1, 2022, 11:00am UTC](https://discuss.elastic.co/t/sorting-multiple-indices-with-different-fields/301315/1 "2022-04-01T11:00:38Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 1, 2022, 12:19pm UTC](https://discuss.elastic.co/t/sorting-multiple-indices-with-different-fields/301315/2 "2022-04-01T12:19:49Z")

</div>

Hi Marten.

Maybe you must use [multi search API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html)

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

---

<div class="post-metadata">

**Author:** ![marten1](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@marten1](https://discuss.elastic.co/u/marten1)\
**Post date:** [April 1, 2022, 12:25pm UTC](https://discuss.elastic.co/t/sorting-multiple-indices-with-different-fields/301315/3 "2022-04-01T12:25:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 4, 2022, 3:16pm UTC](https://discuss.elastic.co/t/sorting-multiple-indices-with-different-fields/301315/4 "2022-04-04T15:16:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marten1](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@marten1](https://discuss.elastic.co/u/marten1)\
**Post date:** [April 5, 2022, 7:42am UTC](https://discuss.elastic.co/t/sorting-multiple-indices-with-different-fields/301315/5 "2022-04-05T07:42:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 6, 2022, 2:27pm UTC](https://discuss.elastic.co/t/sorting-multiple-indices-with-different-fields/301315/6 "2022-04-06T14:27:34Z")

</div>

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

---

<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:** [May 4, 2022, 2:27pm UTC](https://discuss.elastic.co/t/sorting-multiple-indices-with-different-fields/301315/7 "2022-05-04T14:27:43Z")

</div>

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