# NativeSearchQuery exact match sort problems

**URL:** <https://discuss.elastic.co/t/nativesearchquery-exact-match-sort-problems/326256>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [February 23, 2023, 4:46am UTC](https://discuss.elastic.co/t/nativesearchquery-exact-match-sort-problems/326256 "2023-02-23T04:46:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iles983](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@iles983](https://discuss.elastic.co/u/iles983)\
**Post date:** [February 23, 2023, 4:46am UTC](https://discuss.elastic.co/t/nativesearchquery-exact-match-sort-problems/326256/1 "2023-02-23T04:46:57Z")

</div>

Hello everyone. I'm doing search using Java and elasticsearch 6.2.2  
I'm having some troubles with sorting  
The way i need it to be: all exact match sorted by price, with fuzziness 1 sorted by price and then with fuzziness 2 sorted by price.  
But now it's just sorting by price, regardless of scoreMatch

// Here is my code  
\<NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withPageable(pageable)  
.withSort(SortBuilders.scoreSort())  
.withSort(SortBuilders.fieldSort("prices." + requestDto.getDepartmentId()).order(requestDto.getDirection()))  
.withQuery(QueryBuilders.boolQuery()  
.must(QueryBuilders.matchQuery("name", requestDto.getProductName())  
.fuzziness(Fuzziness.AUTO).operator(Operator.AND))  
.mustNot(QueryBuilders.termsQuery("categoryId", categoryBlackList))  
.must(QueryBuilders.termsQuery("categoryId", requestDto.getCategories())))  
.build();

```
    return template.queryForPage(searchQuery, ProductData.class);>

```

Looking forward for help

---

<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:** [March 23, 2023, 4:47am UTC](https://discuss.elastic.co/t/nativesearchquery-exact-match-sort-problems/326256/2 "2023-03-23T04:47:27Z")

</div>

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