Substring search NEST query

Hello, I'm trying to search on an ID in my index with reservations for a test application.
I can search on the full ID but when I search on the last part of the ID (something the PO requested),
I don't get any results back.
This is the querry I have at the moment for search on the last 6 numbers in the ID:

 var test = Repository.ElasticClient.Search<Reservation>(s => s
                           .From(page * numberofresults)
                           .Size(numberofresults)
                           .Query(q => q
                           .Match(r => r
                           .Field(f => f.SequenceId.Substring(9))
                           .Query(IdForSingleSearch))));

LLL-0000-000000
this is the format of the ID

Anyone that knows what could be wrong here?
Thanks in advance

UPDATE:
When I changed the Substring number to 9, I got the last 6 digits.
But my search doesn't find a reservation, and when I look in the cluster it's actually there, anyone any idea why it doesn't find the document?

Thanks in advance

I cases like this you generally have to provide the mapping of the field in Elasticsearch for anyone to be able to help.

Hi thanks for the feedback :slight_smile:
This is the mapping:

            settings.DefaultMappingFor<Reservation>(m => m
                .Ignore(x => x.PartnerInfo)
                .IndexName("reservations_v1")
                .IdProperty(r => r.MaskID)
                .PropertyName(r => r.SequenceId, "sequenceId"));

Please retrieve the mappings through the get mapping API. I am not a .NET developer and prefer seeing exactly what is in Elasticsearch.

@Christian_Dahlqvist
I can retrieve it via the mapping api but it's to long to paste unfortunatly, But I'll paste the mapping for the Sequence ID:

  "SequenceId": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    },
                    "copy_to": [
                        "search_all"
                    ]
                }

Fixed it like this:

var ShortIdSearchReservations = Repository.ElasticClient.Search<Reservation>(s => s
.Query(q => q
.Wildcard(w => w
.Field(f => f.SequenceId)
.Value($"*{IdForSingleSearch}"))));

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