# Field Collapsing not working

**URL:** <https://discuss.elastic.co/t/field-collapsing-not-working/226342>\
**Category:** Elasticsearch\
**Created:** [April 3, 2020, 5:58am UTC](https://discuss.elastic.co/t/field-collapsing-not-working/226342 "2020-04-03T05:58:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jseow](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@jseow](https://discuss.elastic.co/u/jseow)\
**Post date:** [April 3, 2020, 5:58am UTC](https://discuss.elastic.co/t/field-collapsing-not-working/226342/1 "2020-04-03T05:58:24Z")

</div>

Hi,

I'm having some issues with field-collapsing. I tried the following to no avail.

The query:  
{  
"size": 1,  
"from": 1,  
"query": {  
"match": { "model": "Sonic"}  
},  
"sort": [  
{  
"model": "desc"  
}  
],  
"collapse": {  
"field": "model"  
}  
}

An example of a document:

{  
"\_index": "device-2020.04.03",  
"\_type": "\_doc",  
"\_id": "xxxx",  
"\_version": 1,  
"\_score": null,  
"\_source": {  
"ip": "xxx.xxx.xxx.xxx",  
"gateway": "xxx.xxx.xxx.xxx",  
"serial": "xxx",  
"network": "xxx",  
"interface": "xxx",  
"@version": "1",  
"type": "xxx",  
"@timestamp": "2020-04-03T05:48:22.450Z",  
"ip": "xx.xx.xx.xx",  
"usingStaticIp": true,  
"status": "Active",  
"dns": "8.8.8.8, 8.8.4.4",  
"model": "Sonic"  
},  
"fields": {  
"@timestamp": [  
"2020-04-03T05:48:22.450Z"  
]  
},  
"sort": [  
1585892902450  
]  
}

Say, there's 200 documents and I got 10 different models. I want to get the latest doc for each model. Anyone has any idea? I already did the mapping type to ensure model is a keyword.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 3, 2020, 2:02pm UTC](https://discuss.elastic.co/t/field-collapsing-not-working/226342/2 "2020-04-03T14:02:19Z")

</div>

Hey,

can you share a simple reproduction with index creation/mapping, sample documents and the query so others can reproduce? Also the Elasticsearch version you are using would be super useful.

One last thing: The count in `hits.total` will not change, only the documents in the `hits.hits` array.

Thanks!

--Alex

---

<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:** [May 1, 2020, 2:02pm UTC](https://discuss.elastic.co/t/field-collapsing-not-working/226342/3 "2020-05-01T14:02:23Z")

</div>

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