I am trying to convert following ElasticSearch DSL Query to NEST and it seems something is not correct. Here is my DSL Query:
{
"query": {
"multi_match": {
"query": "AJ",
"type": "cross_fields",
"fields": ["name", "shortname", "shortname2", "number"],
"operator": "and"
}
}
}
I have a POCO class. I want to get result as a List as seen below:
public class SearchDto
{
public Guid Id { get; set; }
public string Number { get; set; }
public string Name { get; set; }
public string ShortName2 { get; set; }
public string ShortName1 { get; set; }
}
Since it is a Cross Fields query, I have created fields like this:
Fields nameField = Infer.Field<SearchDto>(p => p.Name);
var shortName2 = Infer.Field<SearchDto>(p => p.ShortName2);
var shortName1 = Infer.Field<SearchDto>(p => p.ShortName1);
var number = Infer.Field<SearchDto>(p => p.Number);
Here is my NEST query:
var searchRequest = new SearchRequest() {
Query = new MultiMatchQuery() {
Fields = nameField
.And(shortName2)
.And(shortName1)
.And(number),
Query = value,
Operator = Operator.And,
Type = TextQueryType.CrossFields
}
}
When I get the Json string for my searchRequest, it only prints "{}" using the following:
var json = _client.RequestResponseSerializer.SerializeToString(searchRequest);
It also posts "{}" as request body
I also tried the following:
var response = _client.Search <List<SearchDto>> (s => s
.Size(500)
.Index("mysearchIndex")
.Query(q => q
.MultiMatch(m => m
.Type(TextQueryType.CrossFields)
.Fields(nameField)
.Fields(shortName1)
.Fields(shortName2)
.Fields(number)
.Operator(Operator.And)
.Query(value)
)
));
Above query posts only "{"size" : 500}" to my elasticsearch endpoint
Can someone please suggest what I am doing wrong and/or suggest better way to handle my query using NEST? It is not even building a full query for some reason.