I am very new to the elastic/ opensearch technologies so pardon me if my understanding is inadequate.
I am trying to implement a search feature using OpenSearch where the user can type in any part of the first few characters of an entry to get the desired document. For example, for an entry like "David", they can type in any of the prefixes like "d", "da", "dav", etc and I have to search the correct document according to it.
I was using a prefix
query for this earlier but now with new added requirements, the search queries need to be analyzed (prefix
being a term query is not analyzed according to the documentation), I can see Elasticsearch has a index_prefixes
parameter for mappings which can be used to generate prefixes for entries (https://www.elastic.co/guide/en/elasticsearch/reference/current/index-prefixes.html), but I cannot find anything equivalent in OpenSearch. The best I could find is to use the search_as_you_type
(https://opensearch.org/docs/latest/field-types/supported-field-types/search-as-you-type/) field that generates a sub field of index_prefix
. But it also generates a 2gram
field which I do not need.
Does OpenSearch
have anything apart from the search_as_you_type
field type to help generate prefixes so that it would make such prefix searches faster?
Or is there any other way this can be implemented efficiently?
You are looking for the edge_ngram tokenizer which helps to deploy autocomplete feature. It exists in both Opensearch and Elasticsearch.
https://opensearch.org/docs/latest/search-plugins/searching-data/autocomplete/#edge-n-gram-matching