3

Having moved from Redis to ElasticSearch for my personal project, I need some help from the masters. The basic requirement is as below:

  1. Indexes contain POCO of type Album which has fields such as Artist, Title, Year
  2. When user enters a search-term, for ex "2", I should get the Albums in which the above fields contain the search-term
  3. It should match Album Title like "2 States", Artists such as "2 Pac" and Year in "2014,1992..etc"

I have got the code working just as expected, but I'm using wildchars which I believe will impact the performance. The code is below:

var results = Client.Search<Album>(body =>
    body.Query(query =>
        query.QueryString(qs =>
            qs.OnFieldsWithBoost(d => d
                .Add(f => f.AlbumName.ToLowerInvariant(), 5.0)
                .Add(f => f.AlbumTitle.ToLowerInvariant(), 2.0)
                )
                .Query(String.Format("{0}*", searchText))
            )
        )
        .Take(100)
    );

Any suggestions to improve the query?

1 Answer 1

1

You need to create an index using the Ngram tokenizer. And then use the search string without wildcard.

Example: How to search for a part of a word with ElasticSearch

Ngram tokenizer: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.