Filter _id range in elasticsearch Filter _id range in elasticsearch elasticsearch elasticsearch

Filter _id range in elasticsearch


Maybe it's a little late, but I try to answer and maybe the answer is still usefull for you.
Seen the comments done for collegues, I think that two main ideas can be extracted:

  1. Generated id by Elasticsearch can't be used to filter or perform any operation other than GET o id search.
  2. Index custom uid value is guessed (and that's the way I'd try to solve the problem)

So, I've coded an example to check if solution 2 is possible. Key parts are these:

#cluster node to queryes = Elasticsearch(['localhost:9200',])records = [    #some custom data]for idx,r in enumerate(records):    _index_config = dict(index_config)    #set Elasticsearch uid    _index_config['_id'] = idx    #replicate in a document field to be able to filter for    r['id'] = idx    kwargs['body'].append({'index' : _index_config})    kwargs['body'].append(r)_ = es.bulk(**kwargs)

Once you have indexed the id field, you can filter by it as you wish. range filter is one of them

elasticsearch_query = {    "query": {        "filtered": {            "filter": {                "range": {                    "id": {                        "gte" : 3,                        "lt"  : 5                    }                }            }        }    }}

You can see a working example in this notebook