Wildcard / regexp in a phrase which has space

Sure.

This is what you want:

DELETE test
PUT test
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "lowercase", "ngram"
          ]
        }
      },
      "filter": {
        "ngram": {
          "type": "edge_ngram",
          "min_gram": 1,
          "max_gram": 20,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "text": {
          "type": "text",
          "analyzer": "my_analyzer",
          "search_analyzer": "simple"
        }
      }
    }
  }
}
PUT test/doc/1
{
  "text": "2 #Quick Foxes lived and died"
}
PUT test/doc/2
{
  "text": "2 #Quick Foxes lived died"
}
PUT test/doc/3
{
  "text": "2 #Quick Foxes lived died and resurrected their wys "
}
PUT test/doc/4
{
  "text": """Sports Report:
Cricket - The Adelaide Strikers have blasted their way back to the top of the Big Bash ladder, after beating the Melbourne Stars."""
}
POST test/_refresh
GET test/_search
{
  "query": {
    "match_phrase": {
      "text": "th wa"
    }
  }
}

It gives:

{
  "took": 13,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1.8853602,
    "hits": [
      {
        "_index": "test",
        "_type": "doc",
        "_id": "4",
        "_score": 1.8853602,
        "_source": {
          "text": "Sports Report:\nCricket - The Adelaide Strikers have blasted their way back to the top of the Big Bash ladder, after beating the Melbourne Stars."
        }
      }
    ]
  }
}
1 Like