'Querying Elasticsearch Arrays with NEST and gRPC protos
My goal is to return a result of a search query to the user. This is done by querying a list of objects in elasticsearch with a custom search parameter in a dotnet 6 webapi project using gRPC proto files and NEST.
My problem is that after the deserialization is done in the background, all properties except the list types have data in them. If I use the EnableDebugMode() and paste the same query in Postman I get the correct results with all properties containing data. My guess is that during the deserialization there are some problems pasting the correct data.
For elasticsearch:
{
"test":{
"aliases":{
},
"mappings":{
"country":{
"properties":{
"countryId":{
"type":"long"
},
"customers":{
"type":"nested",
"properties":{
"customerId":{
"type":"long"
},
"name":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"shortName":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
},
"name":{
"type":"text",
"analyzer":"analyzer-name"
},
"description":{
"type":"text",
"analyzer":"analyzer-name"
}
}
}
},
"settings":{
"index":{
"number_of_shards":"1",
"provided_name":"test",
"creation_date":"1646646283283",
"analysis":{
"analyzer":{
"analyzer-name":{
"filter":"lowercase",
"type":"custom",
"tokenizer":"keyword"
}
}
},
"number_of_replicas":"1",
"uuid":"xyz",
"version":{
"created":"6020499"
}
}
}
}
}
(Multiple customer objects get inserted for each country)
For the dotnet 6 webapi with NEST
private ISearchResponse<Country> GetFilteredResults(ElasticClient client, QueryDto query)
{
return client.Search<Country>(s => s
.From(0)
.Size(10)
.Query(q =>
q.Nested(n => n
.Path(p => p.Customers)
.Query(q => q
.Bool(b => b
.Must(m => m
.MultiMatch(mm => mm
.Fields(fs => fs
.Field(f => f.Customers[0].Name)
.Field(f => f.Customers[0].ShortName))
.Type(TextQueryType.PhrasePrefix)
.Query(query.SearchTerm))))))
)
);
}
and last the grpc proto file:
message Country {
int32 countryId = 1;
string name = 2;
string description = 3;
repeated Customer customers = 4;
}
message Customer {
int32 customerId = 1;
string name = 2;
string shortName = 3;
}
Any ideas what could cause the parsing problem?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
