I have some code connecting to elastic that I'm moving and I thought it would be a good time to migrate from NEST 7.17.4 to Elastic.Client.Elasticsearch 8.19.5 since NEST isn't supported anymore and we'll have no choice but to do this if and when we move to Elasticsearch 9 from our current 8. Note: this is an app that just queries the elastic index. It doesn't and doesn't have to insert or update any records. On the elastic side, mappings do exist if I call the GET from the _mapping endpoint.
However, I'm a bit baffled as to how exactly to handle the missing attribute mapping.
I used to have this:
[Nest.Date(Name = "start")]
public DateTimeOffset DtStart { get; set; }
And everything worked fine. But now I have this since those Nest attributes are no longer available:
[JsonPropertyName("start")]
public DateTimeOffset DtStart { get; set; }
And trying a simple query like this:
var search = client.SearchAsync<Posts>(s => s
.SourceIncludes(fields)
.From(from)
.Size(size)
.Sort(sort => sort.Field(f => f.DtStart, SortOrder.Desc))
.TrackTotalHits(true)
.MaxConcurrentShardRequests(elasticMaxShards)
.Timeout(defaultQueryTimeout)
.AllowPartialSearchResults(false)
, cancel);
Generate the correct query to send to elastic:
{
"from": 0,
"size": 10,
"sort": {
"start": {
"order": "desc"
}
},
"timeout": "30s",
"track_total_hits": true
}
Which works fine the kibana console.
But when I run my app I end up getting:
"No mapping found for [start] in order to sort on"
On the elastic side I can see the mapping looks like this:
"start": {
"type": "date"
}
But I can't quite figure out where and how exactly it needs me to tell it that that's a date field, which I assume is what it gets from the Nest.Date attribute. I have a whole bunch of other fields in by POCO objects that'll need mapping (like [Keyword(Similarity = "boolean", IndexOptions = IndexOptions.Docs)]), but I can't get past this first hurdle to even start thinking about them.
I thought what I needed to do was something like this:
client.Indices.Create<Post>(indexName, index => index
.Mappings(x => x.Properties(ps => ps
.Date(s => s.DtStart))
)
);
But this doesn't seem to work either. Same no mapping error.
I also tried:
client.Indices.Create(indexName, index => index
.Mappings(x => x.Properties(ps => ps
.Date("start"))
)
);
Since my POCO property DtStart isn't start, and still get the same error