# NEST search by guid returning more documentes, how to escape "-" char?

**URL:** https://discuss.elastic.co/t/nest-search-by-guid-returning-more-documentes-how-to-escape-char/67498
**Category:** Elasticsearch
**Created:** [November 29, 2016, 2:51pm UTC](https://discuss.elastic.co/t/nest-search-by-guid-returning-more-documentes-how-to-escape-char/67498 "2016-11-29T14:51:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![agonzalez](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@agonzalez](https://discuss.elastic.co/u/agonzalez)
#### Post date: [November 29, 2016, 2:51pm UTC](https://discuss.elastic.co/t/nest-search-by-guid-returning-more-documentes-how-to-escape-char/67498/1 "2016-11-29T14:51:29Z")

</div>

I am doing a search by a guid but it returns more documents not matching the full guid.

If i search for: 333-600-123-334 it returns any doc containing 600 per example. How can i match the full guid string?

```
        var result = elk.Search<xxxDto>(x => x
            .From(0)
            .Index("index-*")
            .Size(300)
            .AllTypes()
            .Query(q =>
                q.Match(qs => qs.Field("asset_tag").Query("333-600-123-334)))
            .Sort(ss => ss.Descending(p => p.sort_start_time))
            );
```

---

<div class="post-metadata">

### Author: ![agonzalez](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@agonzalez](https://discuss.elastic.co/u/agonzalez)
#### Post date: [December 20, 2016, 12:17am UTC](https://discuss.elastic.co/t/nest-search-by-guid-returning-more-documentes-how-to-escape-char/67498/2 "2016-12-20T00:17:28Z")

</div>

Any tip for this? on how to escape "-"?

---

<div class="post-metadata">

### Author: ![agonzalez](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@agonzalez](https://discuss.elastic.co/u/agonzalez)
#### Post date: [December 20, 2016, 12:19am UTC](https://discuss.elastic.co/t/nest-search-by-guid-returning-more-documentes-how-to-escape-char/67498/3 "2016-12-20T00:19:38Z")

</div>

I am trying to use this: but generates invalid response.

query\_string = "SNMPv2 - SMI::enterprises.21865.1.1.6: "333-600-123-334"";  
q.QueryString(qs =\> qs.Query(query\_string)))

This worksbut returns any doc containing 333 or 666 or 123, etc:

q.Match(qs =\> qs.Field("SNMPv2-SMI::enterprises.21865.1.1.6").Query("333-600-123-334")))

---

<div class="post-metadata">

### Author: ![KodrAus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kodraus/32/22798_2.png) [@KodrAus](https://discuss.elastic.co/u/KodrAus)
#### Post date: [December 27, 2016, 5:15am UTC](https://discuss.elastic.co/t/nest-search-by-guid-returning-more-documentes-how-to-escape-char/67498/4 "2016-12-27T05:15:43Z")

</div>

I believe the problem here is that your guids are tokenised by the `-`, and the query is also being tokenised, so it's finding partial matches for you.

What you want is to match the exact query text, which you can do using a `constant_score` query. See [this article](https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html) for details.

If you're only ever going to query exact guid matches, then you could also disable tokenisation for that field to save some index space.

---

<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: [January 24, 2017, 5:16am UTC](https://discuss.elastic.co/t/nest-search-by-guid-returning-more-documentes-how-to-escape-char/67498/5 "2017-01-24T05:16:03Z")

</div>

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