I currently build a search for a contact list. The user should be allowed to search on any property and get results without typing full words / tokens. After I researched on the topic I found the ngram filter and tried to configure it as shown below:
 $params = [
        'index' => SearchPerson::getIndex(),
        'body' => [
            'settings' => [
                "analysis" => [
                    "analyzer" => [
                        "ngram_analyzer" => [
                            "type" => "custom",
                            "tokenizer" => "whitespace",
                            "filter" => ["asciifolding", "lowercase", "ngram"]
                        ],
                        "whitespace_analyzer" => [
                            "type" => "custom",
                            "tokenizer" => "whitespace",
                            "filter" => [
                                "lowercase",
                                "asciifolding"
                            ]
                        ]
                    ],
                    "filter" => [
                        "ngram" => [
                            "type" => "ngram",
                            "min_gram" => 2,
                            "max_gram" => 20,
                            "token_chars" => [
                                "letter",
                                "digit",
                                "punctuation",
                                "symbol"
                            ]
                        ]
                    ]
                ]
            ],
            'mapping' => [
                'person' => [
                    '_all' => [
                        'index_analyzer' => 'ngram_analyzer',
                        'search_analyzer' => 'whitespace_analyzer'
                    ],
                    'properties' => [
                        'firstname' => [
                            'index_analyzer' => 'ngram_analyzer',
                            'search_analyzer' => 'whitespace_analyzer'
                        ]
                    ]
                ]
            ]
        ]
    ];
When I query the index using this query:
{
  "size": 10,
  "query": {
    "match": {
      "_all": {
        "query": "Terill",
      }
    }
  }
}
i always get this document in return and not the one I intended:
{
[...]
        "firstname": "Austen",
        "lastname": "Braun",
[...]
}
The one I intend to find is the following one:
{
[...]
        "firstname": "Terrill",
        "lastname": "Parker",
[...]
}