# Using FROM option with delete by query

**URL:** https://discuss.elastic.co/t/using-from-option-with-delete-by-query/225925
**Category:** Elasticsearch
**Created:** [March 31, 2020, 5:36pm UTC](https://discuss.elastic.co/t/using-from-option-with-delete-by-query/225925 "2020-03-31T17:36:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ninze](https://avatars.discourse-cdn.com/v4/letter/n/7ab992/32.png) [@ninze](https://discuss.elastic.co/u/ninze)
#### Post date: [March 31, 2020, 5:36pm UTC](https://discuss.elastic.co/t/using-from-option-with-delete-by-query/225925/1 "2020-03-31T17:36:54Z")

</div>

Hi,

I want to keep a max of 1000 latest documents (notifications) for each user. In case the search finds much more than that, I am trying to use "delete by query" to delete excess documents for the user.

The docs for "[delete by query](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html)" say that there is a `from` option:

> (Optional, integer) Starting document offset. Defaults to `0` .

Apparently this is a new feature, as I couldn't find anything related to this option in version 6.8.

I am using elasticsearch PHP client `deleteByQuery()` method with the following params:

```
{
    "index": "user_notification",
    "from": 1000,
    "body": {
        "query": {
            "term": {
                "receiver_id": 77
            }
        },
        "sort": [
            {
                "timestamp": {
                    "order": "desc"
                }
            }
        ]
    }
}

```

and elasticsearch status 400 with an error message:

```
Validation Failed: 
1: using [from] is not allowed in a scroll context;
2: from is not supported in this context;

```

What am I doing wrong?

thanks!

---

<div class="post-metadata">

### Author: ![Mike.Barretta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike.barretta/32/16688_2.png) [@Mike.Barretta](https://discuss.elastic.co/u/Mike.Barretta)
#### Post date: [April 1, 2020, 4:03pm UTC](https://discuss.elastic.co/t/using-from-option-with-delete-by-query/225925/2 "2020-04-01T16:03:07Z")

</div>

@ninze educated guess: have you tried moving `from` under `body`?

---

<div class="post-metadata">

### Author: ![ninze](https://avatars.discourse-cdn.com/v4/letter/n/7ab992/32.png) [@ninze](https://discuss.elastic.co/u/ninze)
#### Post date: [April 1, 2020, 5:07pm UTC](https://discuss.elastic.co/t/using-from-option-with-delete-by-query/225925/3 "2020-04-01T17:07:27Z")

</div>

Yes, even though the docs say it is a query parameter, I tried moving it inside body and it didn't work any better 😉

---

<div class="post-metadata">

### Author: ![ninze](https://avatars.discourse-cdn.com/v4/letter/n/7ab992/32.png) [@ninze](https://discuss.elastic.co/u/ninze)
#### Post date: [April 1, 2020, 5:13pm UTC](https://discuss.elastic.co/t/using-from-option-with-delete-by-query/225925/4 "2020-04-01T17:13:06Z")

</div>

Eventually I got the job done by searching for the 1000th document, then then deleting everything with an older timestamp. But that is 2 roundtrips instead of 1 and a bit more code 🙂 Would still be interested to find out why `from` option doesn't work.

---

<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: [April 29, 2020, 5:13pm UTC](https://discuss.elastic.co/t/using-from-option-with-delete-by-query/225925/5 "2020-04-29T17:13:38Z")

</div>

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