# Substring search NEST query

**URL:** https://discuss.elastic.co/t/substring-search-nest-query/333980
**Category:** Elasticsearch
**Created:** [May 22, 2023, 6:59am UTC](https://discuss.elastic.co/t/substring-search-nest-query/333980 "2023-05-22T06:59:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![LhamoDev](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LhamoDev](https://discuss.elastic.co/u/LhamoDev)
#### Post date: [May 22, 2023, 6:59am UTC](https://discuss.elastic.co/t/substring-search-nest-query/333980/1 "2023-05-22T06:59:09Z")

</div>

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:

```auto
 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

---

<div class="post-metadata">

### Author: ![LhamoDev](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LhamoDev](https://discuss.elastic.co/u/LhamoDev)
#### Post date: [May 22, 2023, 1:47pm UTC](https://discuss.elastic.co/t/substring-search-nest-query/333980/2 "2023-05-22T13:47:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [May 22, 2023, 1:49pm UTC](https://discuss.elastic.co/t/substring-search-nest-query/333980/3 "2023-05-22T13:49:55Z")

</div>

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

---

<div class="post-metadata">

### Author: ![LhamoDev](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LhamoDev](https://discuss.elastic.co/u/LhamoDev)
#### Post date: [May 23, 2023, 6:45am UTC](https://discuss.elastic.co/t/substring-search-nest-query/333980/4 "2023-05-23T06:45:27Z")

</div>

Hi thanks for the feedback 🙂  
This is the mapping:

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

```

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [May 23, 2023, 7:43am UTC](https://discuss.elastic.co/t/substring-search-nest-query/333980/5 "2023-05-23T07:43:01Z")

</div>

Please retrieve the mappings through the [get mapping API](https://www.elastic.co/guide/en/elasticsearch/reference/8.7/indices-get-mapping.html). I am not a .NET developer and prefer seeing exactly what is in Elasticsearch.

---

<div class="post-metadata">

### Author: ![LhamoDev](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LhamoDev](https://discuss.elastic.co/u/LhamoDev)
#### Post date: [May 23, 2023, 7:54am UTC](https://discuss.elastic.co/t/substring-search-nest-query/333980/6 "2023-05-23T07:54:39Z")

</div>

@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:

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

```

---

<div class="post-metadata">

### Author: ![LhamoDev](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LhamoDev](https://discuss.elastic.co/u/LhamoDev)
#### Post date: [May 23, 2023, 12:12pm UTC](https://discuss.elastic.co/t/substring-search-nest-query/333980/7 "2023-05-23T12:12:07Z")

</div>

Fixed it like this:

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

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 20, 2023, 12:12pm UTC](https://discuss.elastic.co/t/substring-search-nest-query/333980/8 "2023-06-20T12:12:55Z")

</div>

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