Need to know how to search in ES using c# searching in arrays Need to know how to search in ES using c# searching in arrays elasticsearch elasticsearch

Need to know how to search in ES using c# searching in arrays


If you are using regular mappings on ES 5 > This will get you results you want. If not you will need to change the mapping.

 QueryContainer query = null;            if(dataToSearch.TagsColours != null && dataToSearch.TagsCars.Length > 0)            {                query = Query<StructuredData>.Terms(t=>t.Field("tagsColours.keyword").Terms(dataToSearch.TagsColours));            }            if(dataToSearch.TagsColours != null && dataToSearch.TagsCars.Length > 0)            {                var q =  Query<StructuredData>.Terms(t=>t.Field("tagsCars.keyword").Terms(dataToSearch.TagsCars));                query = query == null ? q : query && q;             }            if(dataToSearch.TagsKeywords != null && dataToSearch.TagsKeywords.Length > 0)            {                var q =  Query<StructuredData>.Terms(t=>t.Field("tagsKeywords.keyword").Terms(dataToSearch.TagsKeywords));                query = query == null ? q : query && q;             }

The problem you are having is that the term query is done on a non-analyzed value and default text fields use standard analyzer. As of 5 they added keyword sub field that uses the keyword analyzer it essentially just places the terms as is and you can do a search by raw values. The standard analyzer dose tokenization for words and lowercases all the terms so it was unable to find Audi because the term was audi. If you want to just lowercase the input string this will not solve the Mercedes Benz problem since in the standard terms this will became mercedes a benz terms two terms instead of one in other words terms will return results if you put mercedes or benz but not mercedes benz. If you want to da a case insensitive search with the match query you will need to add a custom analyzer.