Search code examples
elasticsearchelasticsearch-dsl

Query DSL regexp pattern doesn't work with some strings


I have a pattern ".TP-V." which returns strings like "SSTP-VPN". But the pattern ".SSH." Does not return anything, although there are lines like "core:Login:SSH:Cisco". I have no idea what pattern is need.


Solution

  • You need to use ".*SSH.*" instead of ".SSH.". Adding a working example -

    Index Data:

    {
        "name":"core:Login:SSH:Cisco"
    }
    {
        "name":"SSTP-VPN"
    }
    

    Search Query:

    {
      "query": {
        "regexp": {
          "name.keyword": {
            "value": ".*SSH.*"
          }
        }
      }
    }
    

    Search Result:

    "hits": [
          {
            "_index": "68015371",
            "_type": "_doc",
            "_id": "2",
            "_score": 1.0,
            "_source": {
              "name": "core:Login:SSH:Cisco"
            }
          }
        ]
    

    Search Query:

    {
      "query": {
        "regexp": {
          "name.keyword": {
            "value": ".*TP-V.*"
          }
        }
      }
    }