# ElasticSearch JAVA create custom sort in place of attribute value sort

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-create-custom-sort-in-place-of-attribute-value-sort/354677>\
**Category:** Elasticsearch\
**Created:** [March 4, 2024, 11:19pm UTC](https://discuss.elastic.co/t/elasticsearch-java-create-custom-sort-in-place-of-attribute-value-sort/354677 "2024-03-04T23:19:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manoj\_Upadhyay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manoj_upadhyay/32/60156_2.png) [@Manoj\_Upadhyay](https://discuss.elastic.co/u/Manoj_Upadhyay)\
**Post date:** [March 4, 2024, 11:19pm UTC](https://discuss.elastic.co/t/elasticsearch-java-create-custom-sort-in-place-of-attribute-value-sort/354677/1 "2024-03-04T23:19:08Z")

</div>

For example, I have 6 accounts (1,2,34,5,6)of transactions in index and I want to search transactions and sort by order by account 4,6,3,2,1,5(custom order ) then how I can use it .

```auto
SearchResponse<MyClass> esResponse = esClient.search((s -> s
                 .index("loans")
                 .size(pageSize)
                 .from(page)
                 .query(q -> q
                     .terms(t -> t
                         .field("ic_number.keyword")
                         .terms(tqf -> tqf.value(/* List<String> here */))
                     )
                 ).sort(so -> so
                     .field(FieldSort.of(f -> f **`<<- is there a way , I can pass customized acc order`** 
                         .field("date_created")
                         .order(SortOrder.Desc)
                     ))
                 )
             ), MyClass.class);

```

---

<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:** [April 1, 2024, 11:19pm UTC](https://discuss.elastic.co/t/elasticsearch-java-create-custom-sort-in-place-of-attribute-value-sort/354677/2 "2024-04-01T23:19:14Z")

</div>

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