# How to use 'Terms' query to return value in my search order?

**URL:** <https://discuss.elastic.co/t/how-to-use-terms-query-to-return-value-in-my-search-order/275052>\
**Category:** Elasticsearch\
**Created:** [June 6, 2021, 6:36am UTC](https://discuss.elastic.co/t/how-to-use-terms-query-to-return-value-in-my-search-order/275052 "2021-06-06T06:36:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sathiez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sathiez/32/89875_2.png) [@sathiez](https://discuss.elastic.co/u/sathiez)\
**Post date:** [June 6, 2021, 6:36am UTC](https://discuss.elastic.co/t/how-to-use-terms-query-to-return-value-in-my-search-order/275052/1 "2021-06-06T06:36:40Z")

</div>

**My doc:**

```auto
{"local_id" : 1654,
"universal_id" : 5412896
}
{
"local_id" : 1657,
"universal_id" : 9658742
}
{
"local_id" : 1658,
"universal_id" : 6325412
}

```

**My query :**

```auto
{"from": 0, "size": 10,"query": {
"bool": {
"must" : [{ 
"terms": { 
"universal_id": [6325412, 5412896, 5412896] 
}}]}}}

```

**My Actual result:**

```auto
 "hits" : [
      {
        "_source" : {
          "local_id" : 1654,
          "universal_id" : 5412896
        }
      },
      {
        "_source" : {
          "local_id" : 1658,
          "universal_id" : 6325412
        }
      }
    ]

```

But I need result as below in my querying order ,

**My Expected result:**

```auto
{ 
       "_source" : {
         "local_id" : 1658,
         "universal_id" : 6325412
       }
     },
     {
       "_source" : {
         "local_id" : 1658,
         "universal_id" : 6325412
       }
     },
 {
       "_source" : {
         "local_id" : 1654,
         "universal_id" : 5412896
       }
     }
   ]

```

How to achieve this in elasticsearch?

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [June 6, 2021, 7:22am UTC](https://discuss.elastic.co/t/how-to-use-terms-query-to-return-value-in-my-search-order/275052/2 "2021-06-06T07:22:12Z")

</div>

Afaik, there is no way to return value in your search order. Why do you need to sort value in your search order?

---

<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:** [July 4, 2021, 7:23am UTC](https://discuss.elastic.co/t/how-to-use-terms-query-to-return-value-in-my-search-order/275052/3 "2021-07-04T07:23:03Z")

</div>

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