0

This should be easy.

I've inserted a number of records into ElasticSearch and have been scouring their documentation but I can't seem to find a way to simply take an index and iterate through it in Node.js

I don't have much experience with Elastic, so it's been frustrating.

Some of the items in that list need to be pruned more or less on a 10 minute basis, otherwise the DB just grows and grows. I'd like a separate task to do just that.

2
  • If you know which items need to be pruned, you don't need to iterate through the whole index, you can simply use the delete by query API Commented May 8, 2017 at 9:02
  • @Val How do I do this by date comparison? Anything with a date older than new Date() should get nuked. Seems like it's just a straight match in the API example - is there more to it? Commented May 8, 2017 at 9:05

1 Answer 1

1

You can achieve what you want by using a range query in your delete by query call:

POST your_index/_delete_by_query
{
  "query": {
    "range" : {
        "date_field" : {
           "lt" : "2017-05-08T00:00:00.000Z"
        }
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Great answer. Silly question: How do I turn the numeric UTC timestamp into "YYYY-MM-DDT00:00:00.000Z" format?
You can also use the numeric timestamp instead of a formatted date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.