Using FROM option with delete by query

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" 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!

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

1 Like

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

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 :slight_smile: Would still be interested to find out why from option doesn't work.

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