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

前端 未结 5 498
孤城傲影
孤城傲影 2021-01-01 23:25

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

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-02 00:14

    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.

提交回复
热议问题