Searching using a column of type number doesn't work


(Guilian Nkamga) #1

Hello,
there is a search field in my website that is used to search objects from type Program.
The Program class contains a Property called ProgramNumber from type integer which is entered by the user to start the search.

My problem is that the search doesn't give me any results when I set the DefaultField to "programNumber". But when I set string field like "name" or "description" as Defaultfield the search works.

Please can you help me to fix this problem?

Here is my code:

public async Task<IEnumerable<T>> Search<T>(string searchTerm) where T : class
    {
        var request = CreateSearchQuery<T>(searchTerm);
        var response = await _elasticClient.SearchAsync<T>(request);

        var items = response.Documents;
        return items;
    }

    private ISearchRequest CreateSearchQuery<T>(string searchTerm) where T : class
    {
        var searchRequest = new SearchRequest<T>(Indices.All, Types.All)
        {
            Size = 10,
            Query = new QueryStringQuery
            {
                DefaultField = "programNumber",
                Query = GetQueryString(searchTerm),
                Fuzziness = Fuzziness.Auto,
                FuzzyPrefixLength = 0,
                FuzzyMaxExpansions = 50,
                Lenient = true,
                AnalyzeWildcard = true,
                DefaultOperator = Operator.Or,
                Boost = 1
            }

        };

        return searchRequest;
    }

Thanks in advance for your help :slight_smile: