# Search\_after doesn't consider the parameter

**URL:** <https://discuss.elastic.co/t/search-after-doesnt-consider-the-parameter/360297>\
**Category:** Elasticsearch\
**Created:** [May 27, 2024, 1:16pm UTC](https://discuss.elastic.co/t/search-after-doesnt-consider-the-parameter/360297 "2024-05-27T13:16:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fatimah](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@fatimah](https://discuss.elastic.co/u/fatimah)\
**Post date:** [May 27, 2024, 1:16pm UTC](https://discuss.elastic.co/t/search-after-doesnt-consider-the-parameter/360297/1 "2024-05-27T13:16:45Z")

</div>

Hello, this is my first topic ever.  
When I run this query it returns 10 documents,(10 is the default number)

```auto
resp = elastic_config.open_point_in_time(index='my_index', keep_alive='1m')
            pit_clause = { 'id': resp['id'], 'keep_alive': '1m'}
            result = elastic_config.search(
                query = {
                    "bool" : {
                        "filter": [
                            {
                                "term" : {
                                    "my_term.keyword": "my_parameter",
                                }},
                            {
                                "term" : {
                                    "my_another_term.keyword": "my_another_parameter",
                                }},
                        ],
                        },
                    },
                    pit = pit_clause,
                    search_after = [1716803519],
                    sort={
                            "@timestamp" : {
                                "order" : "asc"
                            }
                        },request_timeout= 100)

```

and when I run this, it returns 5000 documnts.

```auto
resp = elastic_config.open_point_in_time(index='my_index', keep_alive='1m')
            pit_clause = { 'id': resp['id'], 'keep_alive': '1m'}
            result = elastic_config.search(size=5000,
                query = {
                    "bool" : {
                        "filter": [
                            {
                                "term" : {
                                    "my_term.keyword": "my_parameter",
                                }},
                            {
                                "term" : {
                                    "my_another_term.keyword": "my_another_parameter",
                                }},
                        ],
                        },
                    },
                    pit = pit_clause,
                    search_after = [1716803519],
                    sort={
                            "@timestamp" : {
                                "order" : "asc"
                            }
                        },request_timeout= 100)

```

In fact it doesn't consider the value I'm passing to "search\_after", it just returns documents as many as the size number.  
what's wrong?I want to get documents after the specified time  
version: 7.16.2

---

<div class="post-metadata">

**Author:** ![Sajad\_Soltanian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sajad_soltanian/32/122022_2.png) [@Sajad\_Soltanian](https://discuss.elastic.co/u/Sajad_Soltanian)\
**Post date:** [May 27, 2024, 11:17pm UTC](https://discuss.elastic.co/t/search-after-doesnt-consider-the-parameter/360297/2 "2024-05-27T23:17:38Z")

</div>

It seems that we have understood the search\_after definition wrong.  
as the [document](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html) said, it is used to require us with paginated results, and the `size` field is actually the page size.

above, you have run queries with same `search_after` parameters and different size, which works properly in both cases.

_look at `search_after` somehow as a filter, to filter documents having greater than provided value in their specified field (here `timestamp`)_

---

<div class="post-metadata">

**Author:** ![fatimah](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@fatimah](https://discuss.elastic.co/u/fatimah)\
**Post date:** [May 28, 2024, 10:07am UTC](https://discuss.elastic.co/t/search-after-doesnt-consider-the-parameter/360297/3 "2024-05-28T10:07:40Z")

</div>

Thank you but no it doesn't filter the results based on timestamp here.  
It even returns records earlier than the given value for search\_after.  
It only returns last records as many as the size value

---

<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:** [June 25, 2024, 10:08am UTC](https://discuss.elastic.co/t/search-after-doesnt-consider-the-parameter/360297/4 "2024-06-25T10:08:10Z")

</div>

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