# How can i get another field with sort field?

**URL:** <https://discuss.elastic.co/t/how-can-i-get-another-field-with-sort-field/107483>\
**Category:** Elasticsearch\
**Created:** [November 14, 2017, 4:29am UTC](https://discuss.elastic.co/t/how-can-i-get-another-field-with-sort-field/107483 "2017-11-14T04:29:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacscoding](https://avatars.discourse-cdn.com/v4/letter/z/7bcc69/32.png) [@zacscoding](https://discuss.elastic.co/u/zacscoding)\
**Post date:** [November 14, 2017, 4:29am UTC](https://discuss.elastic.co/t/how-can-i-get-another-field-with-sort-field/107483/1 "2017-11-14T04:29:31Z")

</div>

suppose mapping that  
"user\_access" : {  
"ip" : "[19x.xxx.xxx.xxx](http://19x.xxx.xxx.xxx)",  
"time" : 12312112  
"login\_id" : "somthing id"  
}

So i want to make Terms aggregations with "login\_id" field. becuz i have to know  
multiple ip per login\_id and additional fields : time(last) and ip(at last time doocument).

Its my query.  
{   
"size" : 0,  
"aggs" : {  
"term\_id" : {  
"terms" : {  
"field" : "user\_access.login\_id",  
"order" : {"term\_ip.value" : "desc"}  
},  
"aggs" : {  
"term\_ip" : {  
"cardinality" : {"field" : "user\_access.ip"}  
},  
"last\_access" : {  
"max" : {"field" : "access\_time"}  
}  
}  
}  
}  
}

In my query, i can get last access time field`s value but cant ip(same document)

How can i get ip field ??

---

<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:** [December 12, 2017, 4:29am UTC](https://discuss.elastic.co/t/how-can-i-get-another-field-with-sort-field/107483/2 "2017-12-12T04:29:33Z")

</div>

Closed on December 12, 2017, 4:29am UTC

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