conclusion

We usually use wildcard matching statements. The explanation on the official website is that * is interpreted as:

 `*`, which can match zero or more characters, including an empty one
Copy the code

Website link: www.elastic.co/guide/en/el…

The wildcard character * can be used to match zero or more characters, but I have tested it and found that it cannot match empty strings. In other words, using * in wildcard queries can only match non-empty strings.

validation

Create two instances

POST test/_doc
{
  "t":""
}
POST test/_doc
{
  "t":"hehe"
}
Copy the code

At this point, we have two documents. The field T in one document is an empty string, and the field T in the other document has the content “hehe”. We used wildcard to query:

GET test/_search
{
  "query": {
    "wildcard": {
      "t": {
        "value": "*"
      }
    }
  }
}
Copy the code

Only the document containing hehe was returned, and the other document containing an empty string was not found.

{ "took" : 3, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : {" total ": {" value" : 1, the "base" : "eq"}, "max_score" : 1.0, "hits" : [{" _index ":" test ", "_type" : "_doc", "_id" : "brl6bX8BAQgdLr0hMZEf", "_score" : 1.0, "_source" : {" t ":" hehe "}}}}]Copy the code