# Collapse not working with search\_after with single sort field and PIT

**URL:** <https://discuss.elastic.co/t/collapse-not-working-with-search-after-with-single-sort-field-and-pit/316165>\
**Category:** Elasticsearch\
**Tags:** point-in-time\
**Created:** [October 10, 2022, 3:42am UTC](https://discuss.elastic.co/t/collapse-not-working-with-search-after-with-single-sort-field-and-pit/316165 "2022-10-10T03:42:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reese\_Allison](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reese_allison/32/111860_2.png) [@Reese\_Allison](https://discuss.elastic.co/u/Reese_Allison)\
**Post date:** [October 10, 2022, 3:42am UTC](https://discuss.elastic.co/t/collapse-not-working-with-search-after-with-single-sort-field-and-pit/316165/1 "2022-10-10T03:42:06Z")

</div>

I have an Elastic query that initially returns results. When I attempt the query again using search\_after for paging, I am getting the error: `Cannot use [collapse] in conjunction with [search_after] unless the search is sorted on the same field. Multiple sort fields are not allowed`. So far as I can tell, I am sorting and collapsing using just a single field `per_id`. Is my query structured incorrectly or is there something else I need to do to get this query to run?

```auto
GET /_search
{
    "query": {
        "bool": {
            "must": [{
                "term": {
                    "pform": "iphone"
                }
            }]
        }
    },
    "collapse": {
        "field": "per_id"
    },
    "pit": {
        "id": "g-ABCDDEFG12345678ABCDDEFG12345678==",
        "keep_alive": "5m"
    },
    "sort": [ 
      {"per_id": "asc"}
    ],
    "search_after" : [
      "ABCDDEFG12345678",
      123456
    ]
}

```

---

<div class="post-metadata">

**Author:** ![Reese\_Allison](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reese_allison/32/111860_2.png) [@Reese\_Allison](https://discuss.elastic.co/u/Reese_Allison)\
**Post date:** [October 11, 2022, 3:30pm UTC](https://discuss.elastic.co/t/collapse-not-working-with-search-after-with-single-sort-field-and-pit/316165/2 "2022-10-11T15:30:06Z")

</div>

Passing the sort provided when using a PIT includes a tiebreaker which is more than one field. I needed to programmatically remove the tiebreakers from my search\_after sort to get search\_after to work with collapse.  
So the sort I was provided was:

```auto
    "sort" : [
      "ABCDDEFG12345678",
      123456
    ]

```

So I would use

```auto
    "search_after" : [
      "ABCDDEFG12345678"
    ]

```

---

<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:** [November 8, 2022, 3:30pm UTC](https://discuss.elastic.co/t/collapse-not-working-with-search-after-with-single-sort-field-and-pit/316165/3 "2022-11-08T15:30:50Z")

</div>

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