# Ranking not working for Search query with AllIndices

**URL:** <https://discuss.elastic.co/t/ranking-not-working-for-search-query-with-allindices/206173>\
**Category:** Elasticsearch\
**Created:** [November 1, 2019, 1:30pm UTC](https://discuss.elastic.co/t/ranking-not-working-for-search-query-with-allindices/206173 "2019-11-01T13:30:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gurjit\_buck](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@gurjit\_buck](https://discuss.elastic.co/u/gurjit_buck)\
**Post date:** [November 1, 2019, 1:30pm UTC](https://discuss.elastic.co/t/ranking-not-working-for-search-query-with-allindices/206173/1 "2019-11-01T13:30:48Z")

</div>

Hi, I am using rankfeature for ranking purpose,  
Since there are multiple (4) indexes, the search query result with option AllIndices  
the result is not correctely sorted, seems ranking working for indvisual index and then concat the documents which leads to incorrect order

Please suggest  
`var searchResponse = await elasticClient.SearchAsync(body =\> body  
.AllIndices()  
.Query(qx =\> qx.Bool  
(bb =\> bb.Must(q =\>  
(  
q.Term(x =\> x.Field(f =\> f.ClientId).Value(data.ClientId))  
)  
&&  
(

```
            data.Category == Filters.Tags.ToString() ? q.Terms(c => c.Field(p => p.Tags).Terms(words))
            :
            (data.Category == Filters.Content.ToString() ?
            (
           (q.Term(x => x.Field(f => f.CustomDocType).Value("1")) &&
            (
            (Settings.EnableMultiMatchPharsePrefix ? q.MatchPhrasePrefix(m => m.Field(f => f.Attachment.Content).Query(data.SearchText).Slop(Settings.Slop)) :
            (Settings.EnableFuzziness ? q.MultiMatch(m => m.Fields(f => f.Field(p => p.Attachment.Content)).Fuzziness(Fuzziness.Auto).Query(data.SearchText)) :
            q.MultiMatch(m => m.Fields(f => f.Field(p => p.Attachment.Content)).Query(data.SearchText)))
            )
            ||
            (Settings.EnableWildCard ? (part.Length >= MINIMUM_LENGTH ? (q.Wildcard(f => f.Field(p => p.Attachment.Content.ToLower()).Value("*" + part.ToLower() + "*"))) : null) : null)
            ))
            ||
             (
              q.Term(x => x.Field(f => f.CustomDocType).Value("2")) &&
             (
            (Settings.EnableMultiMatchPharsePrefix ? q.MatchPhrasePrefix(m => m.Field(f => f.Content).Query(data.SearchText).Slop(Settings.Slop)) :
            (Settings.EnableFuzziness ? q.MultiMatch(m => m.Fields(f => f.Field(p => p.Content)).Fuzziness(Fuzziness.Auto).Query(data.SearchText)) :
            q.MultiMatch(m => m.Fields(f => f.Field(p => p.Content)).Query(data.SearchText)))
            )
            ||
            (Settings.EnableWildCard ? (part.Length >= MINIMUM_LENGTH ? (q.Wildcard(f => f.Field(p => p.Content.ToLower()).Value("*" + part.ToLower() + "*"))) : null) : null)
            ))
            )
             :
             null
            )

             ))
      .Should(s => Settings.EnableRanking ? s.RankFeature(r => r.Field(f => f.Rank).Saturation()) : null)

         ))
     .Size(Settings.Size)
      );

```

`

---

<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:** [November 29, 2019, 1:30pm UTC](https://discuss.elastic.co/t/ranking-not-working-for-search-query-with-allindices/206173/2 "2019-11-29T13:30:54Z")

</div>

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