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

前端 未结 5 538
孤城傲影
孤城傲影 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:01

    You can use a wildcard query like this, though it's worth noting that it is not advised to start a wildcard term with * as performance will suffer.

    {
      "query": {
        "wildcard": {
          "_uid": "*000ANT*"
        }
      }
    }
    

    Also note that if the wildcard term you're searching for matches the type name of your documents, using uid will not work, as uid is simply the contraction of the type and the id: type#id

提交回复
热议问题