Elasticsearch equal SQL %Like%

Viewed 12543

Coming from here i'm asking myselve for the elasticsearch syntax for such querys:

WHERE text LIKE "%quick%"
  AND text LIKE "%brown%"
  AND text LIKE "%fox%" 

my try (unfortunately without success)

  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "text": [
                    "*quick*",
                    "*brown*",
                    "*fox*"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
2 Answers

Try using bool and wildcard to do such a query.

{
    "query": {
        "bool": {
            "must": [
                {
                    "wildcard": {
                        "text": "*quick*"
                    }
                },
                {
                    "wildcard": {
                        "text": "*brown*"
                    }
                },
                {
                    "wildcard": {
                        "text": "*fox*"
                    }
                }
            ]
        }
    }
}

Wildcard Query Matches documents that have fields matching a wildcard expression (not analyzed). Supported wildcards are *, which matches any character sequence (including the empty one), and ?, which matches any single character.

That's what you're looking for. Just put desired amount of wildcard queries in your bool/must:

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "text": {
              "value": "*quick*"
            }
          }
        },
        {
          "wildcard": {
            "text": {
              "value": "*brown*"
            }
          }
        },
        {
          "wildcard": {
            "text": {
              "value": "*fox*"
            }
          }
        }
      ]
    }
  }
}
Related