# Indexing and searching on special characters?

**URL:** <https://discuss.elastic.co/t/indexing-and-searching-on-special-characters/9307>\
**Category:** Elasticsearch\
**Created:** [October 10, 2012, 1:39pm UTC](https://discuss.elastic.co/t/indexing-and-searching-on-special-characters/9307 "2012-10-10T13:39:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsandstr](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@tsandstr](https://discuss.elastic.co/u/tsandstr)\
**Post date:** [October 10, 2012, 1:39pm UTC](https://discuss.elastic.co/t/indexing-and-searching-on-special-characters/9307/1 "2012-10-10T13:39:53Z")

</div>

I am having some troubles with how the indexing works on strings. I use normal mapping for strings and query\_string for my queries.

I index the following:

curl -XPUT [http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1) -d '{  
"message": "A&B: This is just a test"  
}'  
curl -XPUT [http://localhost:9200/twitter/tweet/2](http://localhost:9200/twitter/tweet/2) -d '{  
"message": "A+B: This is just a test"  
}'  
curl -XPUT [http://localhost:9200/twitter/tweet/3](http://localhost:9200/twitter/tweet/3) -d '{  
"message": "A-B: This is just a test"  
}'  
curl -XPUT [http://localhost:9200/twitter/tweet/4](http://localhost:9200/twitter/tweet/4) -d '{  
"message": "A_B: This is just a test"  
}'  
curl -XPUT [http://localhost:9200/twitter/tweet/5](http://localhost:9200/twitter/tweet/5) -d '{  
"message": "A&C: This is just a test"  
}'  
curl -XPUT [http://localhost:9200/twitter/tweet/6](http://localhost:9200/twitter/tweet/6) -d '{  
"message": "A+C: This is just a test"  
}'  
curl -XPUT [http://localhost:9200/twitter/tweet/7](http://localhost:9200/twitter/tweet/7) -d '{  
"message": "A-C: This is just a test"  
}'  
curl -XPUT [http://localhost:9200/twitter/tweet/8](http://localhost:9200/twitter/tweet/8) -d '{  
"message": "A_C: This is just a test"  
}'

and I get the following results with my queries:

{'query': {'query\_string': {'query': 'A+B', 'default\_operator': 'AND', 'default\_field': 'message'}}} {u'message': u'A&B: This is just a test'} {u'message': u'A+B: This is just a test'} {u'message': u'A-B: This is just a test'} {u'message': u'A\*B: This is just a test'} --\> I Expected to get only: A+B: This is just a test

{'query': {'query\_string': {'query': 'A&B', 'default\_operator': 'AND', 'default\_field': 'message'}}}  
{u'message': u'A&B: This is just a test'}  
{u'message': u'A+B: This is just a test'}  
{u'message': u'A-B: This is just a test'}  
{u'message': u'A\*B: This is just a test'}  
--\> I Expected to get only: A&B: This is just a test

{'query': {'query\_string': {'query': 'A\*B', 'default\_operator': 'AND', 'default\_field': 'message'}}}  
--\> Got no results at all, this is VERY confusing

{'query': {'query\_string': {'query': 'A-B', 'default\_operator': 'AND', 'default\_field': 'message'}}}  
{u'message': u'A&B: This is just a test'}  
{u'message': u'A+B: This is just a test'}  
{u'message': u'A-B: This is just a test'}  
{u'message': u'A\*B: This is just a test'}  
--\> I Expected to get only: A&B: This is just a test

{'query': {'query\_string': {'query': 'A B', 'default\_operator': 'AND', 'default\_field': 'message'}}}  
{u'message': u'A&B: This is just a test'}  
{u'message': u'A+B: This is just a test'}  
{u'message': u'A-B: This is just a test'}  
{u'message': u'A\*B: This is just a test'}

Why does the query A\*B not return anything at all?  
Is there a simple way to know how special characters are indexed by default?  
It seems to me that A&B, A+B and A-B are all indexed the same way as A B, am I correct?

What about all other characters? How do they behave and how should I construct my query in order to get correct results? Escaping them does not seem to help.

Any help would be appreciated.

Thank you!

- Tommy

---

<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 6, 2017, 3:09am UTC](https://discuss.elastic.co/t/indexing-and-searching-on-special-characters/9307/2 "2017-07-06T03:09:25Z")

</div>


