0

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.

Running the below query in Kibana works as expected.

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}}]}}

But in NEST I cant seem the Read the Reponses, it is always null.

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.
var responses = multiSearchResponse.GetResponse<CustomForm>("custom-form-index"); <!-- Always return null.

I think the mapping is the problem, so it cant create the CustomForm type properly

[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; }
}

Strange thing is if I call it in this format it works, so as a work around I can make multiple requests, but I would like to make it all in one request.

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", "[]")));
R4nc1d
  • 2,923
  • 3
  • 24
  • 44

0 Answers0