0

I need to do string search in Elasticsearch like:

This is the content stored in elasticsearch

and I want it to match with "content stored in" for example, but not with "in stored content". Currently with the simple search both match.

Also I want to match with partial strings like "ontent stor" (not full words).

I know there are things like wildcard search, but they will scan all documents. I'd like to use features to have it run faster.

1 Answer 1

2

Wildcard search are heavy. You can use ngram token filter in your analyzer and do term search. It will take care of matching partial string. Make sure that you use a different analyzer for search(without ngram token filter) if you are not using term search.

Sign up to request clarification or add additional context in comments.

2 Comments

will term search actually match a string without tokenizing it?
If you use the ngram token filter for your index it will generate ngram tokens. For eg: "a simple text" will result in tokens a, "a ", a s, a si', .... si, sim, simp, simpl, ..... and so on. You can refer the doc for more detail. Now when you do a term search it will return the doc if it matches any of the term. In term query your input string does not get analyzed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.