ElasticSearch Low Level Client search using anonymous type

Hi,

We are exploring Elastic search to see if it fits into our application requirements.

We would want to search using anonymous type, here is what i found in the documentation -

var searchResponse = lowlevelClient.Search<StringResponse>("people", PostData.Serializable(new
{
    from = 0,
    size = 10,
    query = new
    {
        wildcard= new
        {
            firstName = new
            {
                value = "Martijn"
            }
        }
    }
}));

var successful = searchResponse.Success;
var responseJson = searchResponse.Body;

I would want to search on firstName.keyword field but i couldn't specify a . (dot)

firstName.keyword

on wildcard search field and it gives a compilation error.

i'm using NEST .NET library.

Any help on this please.

Hi, @gjahagir.

This is possible with anonymous types but requires a workaround because the properties cannot contain period characters. You could achieve it with something like this:

var searchResponse = lowlevelClient.Search<StringResponse>("people", PostData.Serializable(new
{
    from = 0,
    size = 10,
    query = new
    {
        wildcard= new
        {
            firstName = new Dictionary<string, object>
            {
                ["firstname.keyword"] = "Martijn",
            }
        }
    }
}));

Thanks for the help that worked

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.