# Need help with special character search

**URL:** https://discuss.elastic.co/t/need-help-with-special-character-search/306692
**Category:** Elasticsearch
**Created:** [June 8, 2022, 12:06pm UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692 "2022-06-08T12:06:27Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Kapil.Lanjewar](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@Kapil.Lanjewar](https://discuss.elastic.co/u/Kapil.Lanjewar)
#### Post date: [June 8, 2022, 12:06pm UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/1 "2022-06-08T12:06:27Z")

</div>

I have difficulties searching the special characters from my documents.

One of the attribute of the document - "phrase" - contains special characters.

Its value is -\> "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone #&$$$$$."

I am not able to search "#&$$$$$"

Can someone please help in searching such special characters.

I have following mapping -\>

```auto
{
	"properties": {
		"student": {
			"properties": {
				"id": {
					"type": "long"
				},
				"name": {
					"type": "text"
				},
				"email": {
					"type": "text"
				},
				"gender": {
					"type": "text"
				},
				"ip_address": {
					"type": "text"
				},
				"date_of_birth": {
					"type": "date"
				},
				"company": {
					"type": "text"
				},
				"position": {
					"type": "text"
				},
				"experience": {
					"type": "long"
				},
				"country": {
					"type": "text"
				},
				"phrase": {
					"type": "text"
				},
				"salary": {
					"type": "long"
				}
			}
		}
	}
}

```

My query is -\>

```auto
{
  "query": {
    "wildcard": {
      "phrase": {
        "value": "*#&$$$$$.*"
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [June 8, 2022, 12:44pm UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/2 "2022-06-08T12:44:00Z")

</div>

Hi!!

when you don't define the analyzer the 'standard' will be used. It will remove the special characters, run this:

```auto
GET /_analyze
{
  "analyzer": "standard",
  "text": ["The 2 QUICK Brown-Foxes jumped over the lazy dog's bone #&$$$$$."]
}

```

Another option is to use the "whitespace" analyzer that will be able to keep the special character.

```auto
GET /_analyze
{
  "analyzer": "whitespace",
  "text": ["The 2 QUICK Brown-Foxes jumped over the lazy dog's bone #&$$$$$."]
}

```

So you need to make this change:

```auto
    "properties": {
      "phrase": {
        "type": "text",
        "analyzer": "whitespace"
      },

```

---

<div class="post-metadata">

### Author: ![Kapil.Lanjewar](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@Kapil.Lanjewar](https://discuss.elastic.co/u/Kapil.Lanjewar)
#### Post date: [June 8, 2022, 12:52pm UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/3 "2022-06-08T12:52:29Z")

</div>

I have made changes as suggested by you still the query I have posted doesn't return any result. Can you please let me know how can I search the part i.e. "#&$$$$$."

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [June 8, 2022, 12:59pm UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/4 "2022-06-08T12:59:35Z")

</div>

My example:

```auto
PUT teste
{
  "mappings": {
    "properties": {
      "phrase": {
        "type": "text",
        "analyzer": "whitespace"
      }
    }
  }
}

POST teste/_doc
{"phrase":"The 2 QUICK Brown-Foxes jumped over the lazy dog's bone #&$$$$$."}

GET teste/_search
{
  "query": {
    "wildcard": {
      "phrase": {
        "value": "*#&$$$$$.*"
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Kapil.Lanjewar](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@Kapil.Lanjewar](https://discuss.elastic.co/u/Kapil.Lanjewar)
#### Post date: [June 8, 2022, 1:08pm UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/5 "2022-06-08T13:08:31Z")

</div>

> [@RabBit\_BR](#):
>
> ```auto
> {
> "analyzer": "whitespace",
> "text": ["The 2 QUICK Brown-Foxes jumped over the lazy dog's bone #&$$$."]
> }
> 
> ```

I have following documents populated using \_bulk -\>

```auto
{ "index" : { "_index" : "student", "_id" : "1" } }
{"id":1,"name":"Huntlee Dargavel","email":"hdargavel0@japanpost.jp","gender":"male","ip_address":"58.11.89.193","date_of_birth":"11/09/1990","company":"Talane","position":"Research Associate","experience":7,"country":"China","phrase":"Multi-channelled coherent leverage #$$$$$$$$$$","salary":180025}

{ "index" : { "_index" : "student", "_id" : "2" } }
{"id":2,"name":"Othilia Cathel","email":"ocathel1@senate.gov","gender":"female","ip_address":"3.164.153.228","date_of_birth":"22/07/1987","company":"Edgepulse","position":"Structural Engineer","experience":11,"country":"China","phrase":"Grass-rootsheuristichelp-desk#&$$$$$$$$$$","salary":193530}

{ "index" : { "_index" : "student", "_id" : "3" } }
{"id":3,"name":"Winston Waren","email":"wwaren2@4shared.com","gender":"male","ip_address":"202.37.210.94","date_of_birth":"10/11/1985","company":"Yozio","position":"Human Resources Manager","experience":12,"country":"China","phrase":"Versatile object-oriented emulation #$$$$$$$$$$","salary":50616}

{ "index" : { "_index" : "student", "_id" : "4" } }
{"id" : 4,"name" : "Alan Thomas","email" : "athomas2@example.com","gender" : "male","ip_address" : "200.47.210.95","date_of_birth" : "11/12/1985","company" : "Yamaha","position" : "Resources Manager","experience" : 12,"country" : "China","phrase" : "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone #&$$$$$.","salary" : 300000}

```

---

<div class="post-metadata">

### Author: ![Kapil.Lanjewar](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@Kapil.Lanjewar](https://discuss.elastic.co/u/Kapil.Lanjewar)
#### Post date: [June 8, 2022, 1:09pm UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/6 "2022-06-08T13:09:30Z")

</div>

After I upload these documents, my query is failing to return.

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [June 8, 2022, 1:20pm UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/7 "2022-06-08T13:20:31Z")

</div>

You add analyzer in field phrase?  
I will test with your data.

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [June 8, 2022, 4:11pm UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/8 "2022-06-08T16:11:12Z")

</div>

I had successful with your data and you?

---

<div class="post-metadata">

### Author: ![Kapil.Lanjewar](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@Kapil.Lanjewar](https://discuss.elastic.co/u/Kapil.Lanjewar)
#### Post date: [June 9, 2022, 7:12am UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/9 "2022-06-09T07:12:14Z")

</div>

First of all, thank you very much for your help. I am not successful yet. I am thinking probably updating the version of ES may help.

---

<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: [July 7, 2022, 7:12am UTC](https://discuss.elastic.co/t/need-help-with-special-character-search/306692/10 "2022-07-07T07:12:20Z")

</div>

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