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.

dsp_099
  • 5,801
  • 17
  • 72
  • 128
  • 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](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html) – Val May 08 '17 at 09: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? – dsp_099 May 08 '17 at 09:05

1 Answers1

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"
        }
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • Great answer. Silly question: How do I turn the numeric UTC timestamp into "YYYY-MM-DDT00:00:00.000Z" format? – dsp_099 May 08 '17 at 09:15
  • You can also use the numeric timestamp instead of a formatted date. – Val May 08 '17 at 09:15