# Search requests for an exact mach on a value with ampersand

**URL:** https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260
**Category:** Elasticsearch
**Created:** [February 7, 2020, 12:06am UTC](https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260 "2020-02-07T00:06:25Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![StephenGoodall](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@StephenGoodall](https://discuss.elastic.co/u/StephenGoodall)
#### Post date: [February 7, 2020, 12:06am UTC](https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260/1 "2020-02-07T00:06:25Z")

</div>

Hi all,  
I'm trying to resolve an issue we have where the field has an ampersand.  
I did a search on a different field (field\_id)and found this document (edited to remove most of it):  
`{ "_index": "index_v1", "_type": "item", "_id": "aaaaaaaaa", "_score": 1, "_source": { "field_name": "Testing & Ampersand", "field_id": 1234 } }`

But then when I run this request:

```
GET /index_v1/_search
{
    "query" : {
        "term" : { "field_name": "Testing & Ampersand" }
    }
}

```

I get no hits, do i need to escape the ampersand in a specific way? %26 and & seem to have no effect

Cheers

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 7, 2020, 7:46am UTC](https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260/2 "2020-02-07T07:46:52Z")

</div>

What is the data type for `field_name`?  
What analyzer are you using for this field?

---

<div class="post-metadata">

### Author: ![StephenGoodall](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@StephenGoodall](https://discuss.elastic.co/u/StephenGoodall)
#### Post date: [February 7, 2020, 12:38pm UTC](https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260/3 "2020-02-07T12:38:36Z")

</div>

The field is the "keyword" data type and the analyzer is "en\_standard"

Thanks!

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 7, 2020, 1:09pm UTC](https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260/4 "2020-02-07T13:09:36Z")

</div>

It can't be `keyword` with an `analyzer`.  
Are you sure?

---

<div class="post-metadata">

### Author: ![StephenGoodall](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@StephenGoodall](https://discuss.elastic.co/u/StephenGoodall)
#### Post date: [February 7, 2020, 2:00pm UTC](https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260/5 "2020-02-07T14:00:19Z")

</div>

Sorry, I asked a colleague then didn't put the full info on here:

```
"field_name": {
 "type": "text",
 "analyzer": "en_standard",
 "fields": {
  "raw": {
   "type": "keyword"
  }
 }
}

```

the request we send is a query for the field\_name.raw field.

I've since found that if I run:

```
GET /index_v1/_search
{
    "query" : {
        "term" : { "field_name.raw": "Testing & Ampersand" }
    }
}

```

It does return the expected results, I think the issue is that our application that builds and sends the request to elastic is escaping the & to &amp;

Is there anything that you know of in the Java SDK that might be doing this kind of escaping automatically? We use the TransportClient so could it be that using HTTP encoding?

Thanks

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 7, 2020, 2:20pm UTC](https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260/6 "2020-02-07T14:20:17Z")

</div>

> [@StephenGoodall](#):
>
> Is there anything that you know of in the Java SDK that might be doing this kind of escaping automatically?

I don't think so. But if you are getting this value from a web form coming from an user may be there is some transformation before it actually goes to elasticsearch.

> [@StephenGoodall](#):
>
> We use the TransportClient

You should get rid of it. Use the Rest client instead.

---

<div class="post-metadata">

### Author: ![StephenGoodall](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@StephenGoodall](https://discuss.elastic.co/u/StephenGoodall)
#### Post date: [February 10, 2020, 12:18am UTC](https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260/7 "2020-02-10T00:18:01Z")

</div>

Thanks David, we are in the process of moving to the REST client instead 😃

You were right on the transformation issue. The frontend was sending it as "&amp;".

I had put some code in to un-escape the &amp; but I was using the wrong decoder (URL not HTML 🤦‍♂️) , I changed it to a simple replace function and it seems to work now as it sending the corrected value in the request.

Cheers!

---

<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: [March 9, 2020, 12:18am UTC](https://discuss.elastic.co/t/search-requests-for-an-exact-mach-on-a-value-with-ampersand/218260/8 "2020-03-09T00:18:16Z")

</div>

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