How to run multiple search templates using NEST

I am trying perform a multi-template search using NEST, and then read the reponses, but seems like it always returns null when I try to cast it to the POCO type.

The DSL query I run in Kibana looks like this. Just for reference.

GET user-menu-index,custom-form-index,employee-index/_msearch/template
{}
{"id":"user-menu-index-template","params":{"query":"profile","clauses":[]}}
{}
{"id":"custom-form-index-template","params":{"query":"basic","clauses":[]}}
{}
{"id":"employee-index-template","params":{"query":"brenda","clauses":[{"term":{"companyGroupId":1595}}]}}

In NEST it will like like this.

var indexTemplateRequest = new MultiSearchTemplateRequest
{
    Operations = new Dictionary<string, ISearchTemplateRequest>
    {
        {
            "custom-form-index", new SearchTemplateRequest("custom-form-index")
            {
                Id = "custom-form-index-template",
                Params = new Dictionary<string, object>
                {
                    { "query", query },
                    { "clauses", new List<object>() }
                }
            }
        }
    }
};

var multiSearchResponse = this.client.MultiSearchTemplate(indexTemplateRequest); <!-- I can see the results in the reponses, getting returned as a dictionary.

How can I access the reponses, from what I can find online, the following is what i need todo.

var responses = multiSearchResponse.GetResponse<CustomForm>("custom-form-index");

But the above always returns null. I thought maybe there is something wrong with my mappings. But if i change my query to the following

var response = this.client.SearchTemplate<CustomForm>(descriptor =>
                descriptor.Index("custom-form-index")
                    .Id("custom-form-index-template")
                    .Params(objects => objects
                        .Add("query", query)
                        .Add("from", from)
                        .Add("size", size)
                        .Add("clauses", "[]")));

I get the correct result back, but in this way i am just searching on one template i would like todo it multiple templates with one request.

My mappings file looks as follow.

[ElasticsearchType(RelationName = "customForm")] <!-- Not sure if the RelationName should be camel-case or not.
public class CustomForm
{
    [Text(Name = "companyId")] <!-- Added the types manually to see if it would make a difference
    public long CompanyId { get; set; }

    [Text(Name = "companyLevel")]
    public bool CompanyLevel { get; set; }

    [Text(Name = "employeeLevel")]
    public bool EmployeeLevel { get; set; }

    [Text(Name = "collectionName")]
    public string CollectionName { get; set; }

    [Text(Name = "customFormScreenType")]
    [Column("fkCustomFormScreenTypeID")]
    public CustomFormScreenTypes CustomFormScreenType { get; set; } = CustomFormScreenTypes.CustomForms;

    [Text(Name = "pageName")]
    public string PageName { get; set; }

    [Text(Name = "url")]
    public string Url { get; set; }
}

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