SQL like in elastic

Is it possible to search in elastic like "SQL LIKE" works ?? I have tried to search with wildcard but it is not working if there are spaces in word. Can I somehow adjust the wildcard usage to that case?

It's not recommended but if you want it do that against a keyword field data type or don't analyze the field.

i have tried this way

    DELETE wildcardtest

    PUT /wildcardtest
    {
      "mappings": {
        "doc": {
          "properties": {
            "name": {
              "type": "keyword"
            }
          }
        }
      }
    }
    PUT wildcardtest/doc/1
    {
      "name": "Armenian Dram"
    }
    PUT wildcardtest/doc/2
    {
      "name": "US Dollar"
    }

    GET wildcardtest/_search
    {
       "query": {
        "wildcard": {
          "name": "*ian dram*"
        }
      }
    }

but i don't get any result

It's because your text is not analyzed.

This one works:

GET wildcardtest/_search
{
   "query": {
    "wildcard": {
      "name": "*ian Dram*"
    }
  }
}

If you really want to do that, you need may be to lowercase the content by using a lowercase normalizer or change the type to text and use a simple analyzer.

if i change type to text and also use lowercase normalizer wildcard will not work with space ... okey if it's not recommended use wildcard with spaces how can i get "SQL like" effect with elastic

May be explain the use case so we can help to find a better approach?

By use case I mean: what type of documents, what are your users going to enter in the search bar, ...

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.