pattern matching in elastic search?

前端 未结 2 1447
醉酒成梦
醉酒成梦 2021-01-23 07:53

Continuing from my earlier post, I have changed the query as according to femtoRgon\'s post some characters and anchors are not supported by elastic search.

I am looking

2条回答
  •  星月不相逢
    2021-01-23 08:28

    Seeing as ^, $ and \d can't be used, I would do this:

    [^0-9-][0-9]{3}-[0-9]{2}-[0-9]{4}[^0-9-]
    

    Or in Java:

    FilterBuilders.regexpFilter("_all", "[^0-9-][0-9]{3}-[0-9]{2}-[0-9]{4}[^0-9-]"));
    

    Which checks that before or after the found number are no other numbers or dashes. It does require there be some character before and after the match though, so this won't capture documents that have the social security number as the very beginning or very end.

    Regex101 demo

提交回复
热议问题