RMass
RMass

Reputation: 177

NEST Match Query Issue

I'm currently working on a NEST searcher for a phones database. I've had very little luck with the dynamic version of things in terms of making it so that a user can filter certain terms to search for in the frontend.

This is because NEST doesn't like replacing a field "f.something" with a variable. Due to this I've gone to static because I believe I can do that with some object instantiation.

However, now even though I'm getting valid NEST responses back they're always empty even though there's obviously a result to be had. Such as "Name" for field and "iPhone" for query. What am I missing? Thanks in advance.

P.S. The commented-out code used to have "bool" and "should" checks in but similarly I kept getting no results.

private ISearchResponse<MasterProduct> SearchThis(ElasticClient client, string query, string field, int pageSize, int recordNumber)
        {
            var searchLayout = new SearchRequest<MasterProduct>
            {
                Size = pageSize,
                From = recordNumber,
                Query = new MatchQuery
                {
                    Field = field,
                    Query = query,
                    Fuzziness = Fuzziness.Auto,
                    PrefixLength = 2,
                    Lenient = true,
                    FuzzyRewrite = MultiTermQueryRewrite.TopTermsBlendedFreqs(10)
                }
            };
            var searchResponse = client.Search<MasterProduct>(searchLayout);
            return searchResponse;
            }

            /*var searchResponse = client.Search<MasterProduct>(s => s
                .From(recordNumber)
                .Size(pageSize)
                .Query(q => q
                .Match(a => a
                    .Field(f => f.MasterProductName) 
                    .Query(query)
                    .Fuzziness(Fuzziness.Auto)
                    .PrefixLength(2)
                    .Fuzziness(Fuzziness.Auto)
                    .Lenient()
                    .FuzzyRewrite(MultiTermQueryRewrite.TopTermsBlendedFreqs(10))
                    )

                .Match(b => b
                    .Field(f => f.ManufacturerName)
                    .Query(query)
                    .Fuzziness(Fuzziness.Auto)
                    .PrefixLength(2)
                    .Fuzziness(Fuzziness.Auto)
                    .Lenient()
                    .FuzzyRewrite(MultiTermQueryRewrite.TopTermsBlendedFreqs(10))
                    )

                .Match(c => c
                    .Field(f => f.MasterAttributes)
                    .Query(query)
                    .Fuzziness(Fuzziness.Auto)
                    .PrefixLength(2)
                    .Fuzziness(Fuzziness.Auto)
                    .Lenient()
                    .FuzzyRewrite(MultiTermQueryRewrite.TopTermsBlendedFreqs(10))
                    )
                )
            );
            Console.WriteLine(searchResponse.Hits.Count());

            foreach (var hit in searchResponse.Documents)

            {

                Console.WriteLine(hit.MasterProductId);

            }*/
    }

Upvotes: 0

Views: 456

Answers (1)

RMass
RMass

Reputation: 177

@RussCam answered the question in the comments above. To reiterate, pass only strings in as parameters to fields, not other datatypes. Camelcase is also necessary for this to work.

Upvotes: 0

Related Questions