Welcome to the navigation

Sunt nisi ad dolor commodo consectetur excepteur laboris sint dolore eiusmod voluptate nostrud cupidatat lorem nulla labore magna qui aliqua, enim tempor occaecat ipsum ut. Ad duis est voluptate commodo in excepteur aliquip nisi in fugiat quis proident, nulla nostrud cillum ipsum velit laborum, ut amet, consectetur reprehenderit ut aute

Yeah, this will be replaced... But please enjoy the search!

Episerver Find error 400 when using synonyms

I got a 400 error from Episerver Find when I published ran my search implementation on a customer test environment. The only thing that was different from my development environment (where the code worked) was the Find Index.

Excerpt of the exception

The remote server returned an error: (400) Bad Request.
SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;

Well that didn't say anything. The query generating the exception

var lang = Thread.CurrentThread.CurrentCulture;

var language =
        .FirstOrDefault(x => 
            x.Name.Equals(lang.Name, StringComparison.CurrentCultureIgnoreCase));

var query = SearchClient.Instance.UnifiedSearch(language: Language.language)
    .AndInField(x => x.SearchCategories)

Since this is placed in a Web Api I use the Thread Culture to be able to resolve the correct language, next I fetched the language from the Language class. This is similar to stating the language using the static properties

SearchClient.Instance.UnifiedSearch(language: Language.English)

There's nothing wrong with the query itself and the language branches are clearly visible in the Find Overview. 

I forgot that Find doesn't work that way and that this view is in no way related to your service settings. Since I have no access to the index service settings I had to rely on the api's to check the service configuration.

Available language branches

The following query helped me out

// construct a searchClient using IClient
IClient _searchClient = Client.CreateFromConfig(); var languages = _searchClient.Settings.Languages;

// or by using the singleton
var languages = SearchClient.Instance.Settings.Languages;

When using my developer index I had two languages

And when using the index from the test environment I only had swedish

This means that

  • Find will allow you to send multiple languages to the index regardless of your language branch settings
  • Find will allow you to fetch any page that is indexed regardless of your language branch settings as long as you do not state a language that isn't configured in the settings
  • Find will not allow you to run complex language specific queries on languages that are not setup in the index service

The last bullet is where my query failed, if I remove the UsingSynonyms extension from the query it runs just fine, except from not returning any results of course since I had set the language parameter. 


First of all, dont use the pattern I used above, instead use IClient settings. Second, contact Episerver and tell them to re-configure your index with the missing languages.

var lang = Thread.CurrentThread.CurrentCulture; // or whatever works for you

var query = SearchClient.Instance.UnifiedSearch(
        language: SearchClient.Instance.Settings.Languages.GetSupportedLanguage(lang) // possibly use the SearchClient.Instance singleton instead 
                    ?? Language.None)
    .AndInField(x => x.SearchCategories) // maybe

var result = query.GetResult();

Much better!