How to do a wildcard or regex match on _id in elasticsearch

elasticsearch

From below sample elasticsearch data I want to apply wildcard say *.000ANT.* on _id so as to fetch all docs whose _id contains 000ANT. Please help.

"hits": [
  {
    "_index": "data_collector",
    "_type": "agents",
    "_id": "Org000LAN_example1.com",
    "_score": 1,
    "fields": {
      "host": [
        "example1.com"
      ]
    }
  },
  {
    "_index": "data_collector",
    "_type": "agents",
    "_id": "000BAN_example2.com",
    "_score": 1,
    "fields": {
      "host": [
        "example2.com"
      ]
    }
  },
  {
    "_index": "data_collector",
    "_type": "agents",
    "_id": "000ANT_example3.com",
    "_score": 1,
    "fields": {
      "host": [
        "example3.com"
      ]
    }
  }
]

Best Solution

This is just an extension on Andrei Stefan's answer

{
  "query": {
    "script": {
      "script": "doc['_id'][0].indexOf('000ANT') > -1"
    }
  }
}

Note: I do not know the performance impact of such a query, most probably this is a bad idea. Use with caution and avoid if possible.

Related Question