# Query multiple indices with different fields to sort

**URL:** <https://discuss.elastic.co/t/query-multiple-indices-with-different-fields-to-sort/292969>\
**Category:** Elasticsearch\
**Created:** [December 27, 2021, 12:07pm UTC](https://discuss.elastic.co/t/query-multiple-indices-with-different-fields-to-sort/292969 "2021-12-27T12:07:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlp1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jlp1/32/6607_2.png) [@jlp1](https://discuss.elastic.co/u/jlp1)\
**Post date:** [December 27, 2021, 12:07pm UTC](https://discuss.elastic.co/t/query-multiple-indices-with-different-fields-to-sort/292969/1 "2021-12-27T12:07:26Z")

</div>

Hello I am using Elasticsearch 7.10.0 and trying to solve following problem:  
I have several indices and need to get documents from all of them matching different queries (5-15 queries against each index). However, depending on a query, it can be different field to sort on.

I also need to apply paging and have duplicates when a document matches more than one query. I need to know which query have been matched.

My first idea is to use multi query and have separate queries but I need paging of complete results and not each individual query result.

My second idea is to have one big query, join with 'should' but I am not sure if this is possible to define order on each should clause. Additionaly I need duplicates but 'should' clause will return a document first time it is matched.

Any other ideas?

---

<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:** [January 24, 2022, 12:07pm UTC](https://discuss.elastic.co/t/query-multiple-indices-with-different-fields-to-sort/292969/2 "2022-01-24T12:07:29Z")

</div>

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