I had to do this on a project back in Litium 7.2, don’t know if it’s a better way: || qc.MatchPhrasePrefix(x => x.Field(z => z.ModelNames).Query(searchQuery.Text).Boost(1).MaxExpansions(100))
Its working for Name, but when including ArticleNumber also I get an error from the Elasticsearch instance:
The remote server returned an error: (400) Bad Request.. Call: Status code 400 from: POST /prjproductdocument.sv-se/_search?typed_keys=true. ServerError: Type: search_phase_execution_exception Reason: "all shards failed"
Also I wonder if this solution works with synonyms?
For me, article number did not work at all, so i replaced it with a new field in the index and added this:
|| qc.MatchPhrasePrefix(x => x.Field(z => z.SearchableArticleNumber)
The searching is dependent on the types of the fields that exists in the model. If we have the default ProductDocument-model from Accelerator we can see that the ArticleNumber property is decorated with the Keyword-attribute and that it not is supposed to use other than direct hits.
when it came to searching strings, Elasticsearch has broadly offered two choices:
Text fields
Keyword fields
Text fields “tokenize” strings into multiple tokens, each typically representing words. Searchers looking for quick foxes can therefore match articles talking about a quick brown fox .
Keyword fields tend to be used for shorter, structured content like a country code which would be indexed without analysis as a single token. These can then be used by analysts e.g. to visualize popular holiday destinations using aggregations .