Cant get Search to work with .NET 9 Client

Hi, new to Elastic Search so I'm a bit stuck, I have indexed som documents and I can see mappings are created for all properties for my document. (might not be optimal right now but just testing this out right now)

So I have indexed 10 test documents and I can see them if I do

var reponse = _client.Indices.Get(_indexFind);

or

var reponse = _client.Search<ElasticSearchFindDto>(s => s
    .Indices(_indexFind)
    .Query(q =>
        q.Bool(b => 
            b.Filter(f => 
                f.MatchAll()
            )
        )
    )
);

But if I try to match the search on a field I keep getting 0 hits.

var reponse2 = _client.Search<ElasticSearchFindDto>(s => s
    .Indices(_indexFind)
    .Query(q =>
        q.Bool(b => 
            b.Filter(f => 
                f.Match(m=> 
                    m.Field("RegNo").Query("RegNo_1"))
            )
        )
    )
);

What am I missing, have spent hours on this now and I cant get any of my multiple ways I tried this to return anything.

I have tried multiple solutions but this does look like the most logical criteria, as I want to check if a field has a value and if true return it as part of query.

Appreciate more insight what I am mission or doing wrong, feels like something fundamental. :slight_smile:

Hello @c77m

Welcome to the community!!

Could you please share the mapping details on Elastic for the one which you are executing the query :

 f.Match(m=> 
                    m.Field("RegNo").Query("RegNo_1"))

Mapping of field "RegNo" & the document where we have the value "RegNo_1"

Thanks!!

Thanks for the reply, I did figure it out last night.

Reason is in my Document my properties are PascalCase but Elastic for some reason map them as CamelCase.

As soon as I search for regNo all works as expected. Anyway to make Elastic map the properties in PascalCase. Im sort of using Reflection to dynamically build the Query. Made a workaround for now to convert property name to CamelCase so now it seems to work as expected.

1 Like