# Define ordering in wildcard query

**URL:** <https://discuss.elastic.co/t/define-ordering-in-wildcard-query/285601>\
**Category:** Elasticsearch\
**Created:** [September 30, 2021, 2:12pm UTC](https://discuss.elastic.co/t/define-ordering-in-wildcard-query/285601 "2021-09-30T14:12:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![v\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/v_kumar/32/94646_2.png) [@v\_kumar](https://discuss.elastic.co/u/v_kumar)\
**Post date:** [September 30, 2021, 2:12pm UTC](https://discuss.elastic.co/t/define-ordering-in-wildcard-query/285601/1 "2021-09-30T14:12:24Z")

</div>

Hi,  
In one of our use-case we're using a wildcard query on a field("cmpy") with searchQuery(_val_). Let's say values on different documents for "cmpy" field is "val", "1 val", "a value". Ask is, is there a way to order the results such as exactly matched text("val") should be on top & then followed by other documents? Tried "rewrite" as well but couldn't able to get "val" on top of the results.

Es\_version: 6.4

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 30, 2021, 3:10pm UTC](https://discuss.elastic.co/t/define-ordering-in-wildcard-query/285601/2 "2021-09-30T15:10:23Z")

</div>

You could use ngram or edge ngram based analyzers to index your field in addition to the default analyzer.  
Then you can query both fields and boost if neede the field with exact match.

Some examples at:

> <https://gist.github.com/dadoonet/1a599c3e68420aa95ade73fe58b9e0a1>
>
> There are more than three files. show original

> Es\_version: 6.4

It's urgent that you upgrade to at the very least 6.8 or better 7.15.0.

---

<div class="post-metadata">

**Author:** ![v\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/v_kumar/32/94646_2.png) [@v\_kumar](https://discuss.elastic.co/u/v_kumar)\
**Post date:** [September 30, 2021, 5:11pm UTC](https://discuss.elastic.co/t/define-ordering-in-wildcard-query/285601/3 "2021-09-30T17:11:44Z")

</div>

Got it. @dadoonet Thanks for your reply. Yes David we'll be updating our ES version to the latest in the coming months.

---

<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:** [October 28, 2021, 5:11pm UTC](https://discuss.elastic.co/t/define-ordering-in-wildcard-query/285601/4 "2021-10-28T17:11:56Z")

</div>

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