# Unable to search text containing only special characters using elasticsearch query

**URL:** <https://discuss.elastic.co/t/unable-to-search-text-containing-only-special-characters-using-elasticsearch-query/62200>\
**Category:** Elasticsearch\
**Created:** [October 4, 2016, 5:40pm UTC](https://discuss.elastic.co/t/unable-to-search-text-containing-only-special-characters-using-elasticsearch-query/62200 "2016-10-04T17:40:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhisheknath07](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@abhisheknath07](https://discuss.elastic.co/u/abhisheknath07)\
**Post date:** [October 4, 2016, 5:40pm UTC](https://discuss.elastic.co/t/unable-to-search-text-containing-only-special-characters-using-elasticsearch-query/62200/1 "2016-10-04T17:40:08Z")

</div>

Hi,

Here is my index with settings and mappings

curl -XPUT '[http://localhost:9200/special\_index](http://localhost:9200/special_index)' -d '{  
"settings": {  
"numberOfShards": "5",  
"numberOfReplicas": "1",  
"analysis": {  
"filter": {  
"edge\_ngram\_filter": {  
"type": "edge\_ngram",  
"min\_gram": "1",  
"max\_gram": "100",  
"token\_chars": [  
"letter"  
]  
},  
"word\_delimiter\_for\_phone": {  
"type": "word\_delimiter",  
"catenate\_all": true,  
"generate\_number\_parts ": false,  
"split\_on\_case\_change": false,  
"generate\_word\_parts": false,  
"split\_on\_numerics": false,  
"preserve\_original": true  
}  
},  
"analyzer": {  
"edge\_ngram\_analyzer": {  
"type": "custom",  
"filter": [  
"lowercase",  
"edge\_ngram\_filter",  
"word\_delimiter\_for\_phone"  
],  
"tokenizer": "whitespace"  
},  
"case\_insensitive\_sort\_analyzer": {  
"type": "custom",  
"tokenizer": "keyword",  
"filter": [  
"lowercase"  
]  
}  
}  
}  
},  
"mappings": {  
"documents": {  
"properties": {  
"id": {  
"type": "string",  
"index\_analyzer": "edge\_ngram\_analyzer",  
"search\_analyzer": "standard",  
"fields": {  
"sort": {  
"type": "string",  
"analyzer": "case\_insensitive\_sort\_analyzer"  
}  
}  
},  
"name": {  
"type": "string",  
"index\_analyzer": "edge\_ngram\_analyzer",  
"search\_analyzer": "standard",  
"fields": {  
"sort": {  
"type": "string",  
"analyzer": "case\_insensitive\_sort\_analyzer"  
}  
}  
}  
}  
}  
}  
}'

Now inserted the below documents

curl -XPUT '[http://localhost:9200/special\_index/documents/1](http://localhost:9200/special_index/documents/1)' -d '{ "id": "101", "name": "abcd" }'  
curl -XPUT '[http://localhost:9200/special\_index/documents/2](http://localhost:9200/special_index/documents/2)' -d '{ "id": "102", "name": "abc" }'  
curl -XPUT '[http://localhost:9200/special\_index/documents/3](http://localhost:9200/special_index/documents/3)' -d '{ "id": "103", "name": "@#$%" }'  
curl -XPUT '[http://localhost:9200/special\_index/documents/4](http://localhost:9200/special_index/documents/4)' -d '{ "id": "104", "name": "@#$%" }'  
curl -XPUT '[http://localhost:9200/special\_index/documents/5](http://localhost:9200/special_index/documents/5)' -d '{ "id": "104", "name": "@#$%xyz" }'

When I search for name containing only alphabets and alphabets + special characters using elasticsearch query dsl it works.

curl -XGET '[http://localhost:9200/special\_index/documents/\_search?pretty](http://localhost:9200/special_index/documents/_search?pretty)' -d '{"query":{"query\_string":{ "query": "name:@#$%xyz"}}}'

curl -XGET '[http://localhost:9200/special\_index/documents/\_search?pretty](http://localhost:9200/special_index/documents/_search?pretty)' -d '{"query":{"query\_string":{ "query": "name:abcd"}}}'

**But when I search for text containing only special characters it does not work. Kindly advise how to search for text containing only special characters.**

**curl -XGET '[http://localhost:9200/special\_index/documents/\_search?pretty](http://localhost:9200/special_index/documents/_search?pretty)' -d '{"query":{"query\_string":{ "query": "name:@#$%"}}}'**

Thanks in Advance,  
Abhishek

---

<div class="post-metadata">

**Author:** ![abhisheknath07](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@abhisheknath07](https://discuss.elastic.co/u/abhisheknath07)\
**Post date:** [October 5, 2016, 10:25am UTC](https://discuss.elastic.co/t/unable-to-search-text-containing-only-special-characters-using-elasticsearch-query/62200/2 "2016-10-05T10:25:03Z")

</div>

I able to to fix the issue with some change in mappings and settings. Please find the details below.

curl -XPUT '[http://localhost:9200/special\_chars\_index](http://localhost:9200/special_chars_index)' -d '{  
"settings": {  
"numberOfShards": "5",  
"numberOfReplicas": "1",  
"analysis": {  
"filter": {  
"edge\_ngram\_filter": {  
"type": "edge\_ngram",  
"min\_gram": "1",  
"max\_gram": "100",  
"token\_chars": [  
"letter", "digit"  
]  
},  
"word\_delimiter\_filter": {  
"type": "word\_delimiter",  
"catenate\_all": true,  
"generate\_number\_parts ": false,  
"split\_on\_case\_change": false,  
"generate\_word\_parts": false,  
"split\_on\_numerics": false,  
"preserve\_original": true  
}  
},  
"analyzer": {  
"index\_edge\_ngram\_analyzer": {  
"type": "custom",  
"filter": [  
"lowercase",  
"edge\_ngram\_filter"  
],  
"tokenizer": "whitespace"  
},  
"search\_word\_delimiter\_analyzer": {  
"type": "custom",  
"filter": [  
"lowercase",  
"word\_delimiter\_filter"  
],  
"tokenizer": "whitespace"  
},  
"case\_insensitive\_sort\_analyzer": {  
"type": "custom",  
"tokenizer": "keyword",  
"filter": [  
"lowercase"  
]  
}  
}  
}  
},  
"mappings": {  
"documents": {  
"properties": {  
"id": {  
"type": "string",  
"index\_analyzer": "index\_edge\_ngram\_analyzer",  
"search\_analyzer": "search\_word\_delimiter\_analyzer",  
"fields": {  
"sort": {  
"type": "string",  
"analyzer": "case\_insensitive\_sort\_analyzer"  
}  
}  
},  
"name": {  
"type": "string",  
"index\_analyzer": "index\_edge\_ngram\_analyzer",  
"search\_analyzer": "search\_word\_delimiter\_analyzer",  
"fields": {  
"sort": {  
"type": "string",  
"analyzer": "case\_insensitive\_sort\_analyzer"  
}  
}  
},  
"type": {  
"type": "string",  
"index": "not\_analyzed",  
"fields": {  
"sort": {  
"type": "string",  
"analyzer": "case\_insensitive\_sort\_analyzer"  
}  
}  
}  
}  
}  
}  
}'

curl -XPUT '[http://localhost:9200/special\_chars\_index/documents/1](http://localhost:9200/special_chars_index/documents/1)' -d '{ "id": "101", "name": "abcd", "type": "pqrs" }'  
curl -XPUT '[http://localhost:9200/special\_chars\_index/documents/2](http://localhost:9200/special_chars_index/documents/2)' -d '{ "id": "102", "name": "abc", "type": "pqr" }'  
curl -XPUT '[http://localhost:9200/special\_chars\_index/documents/3](http://localhost:9200/special_chars_index/documents/3)' -d '{ "id": "103", "name": "@#$%", "type": "@#$%" }'  
curl -XPUT '[http://localhost:9200/special\_chars\_index/documents/4](http://localhost:9200/special_chars_index/documents/4)' -d '{ "id": "@#$%", "name": "@#$%", "type": "@#$%" }'  
curl -XPUT '[http://localhost:9200/special\_chars\_index/documents/5](http://localhost:9200/special_chars_index/documents/5)' -d '{ "id": "@#$%xyz", "name": "@#$%xyz", "type": "@#$%abc" }'  
curl -XPUT '[http://localhost:9200/special\_chars\_index/documents/6](http://localhost:9200/special_chars_index/documents/6)' -d '{ "id": "abcd", "name": "()&_^%$#@!+\>\<;??//\_==abcd", "type": "pqrs" }'  
curl -XPUT '[http://localhost:9200/special\_chars\_index/documents/7](http://localhost:9200/special_chars_index/documents/7)' -d '{ "id": "abc", "name": "()&_^%$#@!+\>\<;??//\_==", "type": "pqr" }'

curl -XGET '[http://localhost:9200/special\_chars\_index/documents/\_search?pretty](http://localhost:9200/special_chars_index/documents/_search?pretty)' -d '{"query":{"query\_string":{ "query": "name:\@\#\$\%"}}}'

---

<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 5, 2017, 10:14pm UTC](https://discuss.elastic.co/t/unable-to-search-text-containing-only-special-characters-using-elasticsearch-query/62200/3 "2017-07-05T22:14:46Z")

</div>


