# I want to index elasticsearch query

**URL:** <https://discuss.elastic.co/t/i-want-to-index-elasticsearch-query/10879>\
**Category:** Elasticsearch\
**Created:** [February 25, 2013, 12:46pm UTC](https://discuss.elastic.co/t/i-want-to-index-elasticsearch-query/10879 "2013-02-25T12:46:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdo](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@abdo](https://discuss.elastic.co/u/abdo)\
**Post date:** [February 25, 2013, 12:46pm UTC](https://discuss.elastic.co/t/i-want-to-index-elasticsearch-query/10879/1 "2013-02-25T12:46:19Z")

</div>

Hi all

I want to index a string like the following (' "myname" : "Abdulmuhaimen"  
'), which contains the special characters " and :, when i escape them using  
, the \ is retrieved as well when geting back the text from the  
elasticsearch (i.e. I index the text like "myname":"Abdulmuhaimen" and  
get the same when retrieving it including the escape character). I want to  
index such text and get back "myname" : "Abdulmuhaimen" when searching for  
it without the escape character. Any help is appreciated.

Thanks in advance

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [February 25, 2013, 3:23pm UTC](https://discuss.elastic.co/t/i-want-to-index-elasticsearch-query/10879/2 "2013-02-25T15:23:33Z")

</div>

You'll have to run the result through your language's equivalent of  
"json\_decode". The results returned by Elasticsearch are packaged in a  
JSON object, so any data within has to be JSON compliant (which means  
escaping characters inside of fields):

$ curl -XPOST localhost:9200/test/test/ -d '  
{  
"newfield" : ""myname" : "Abdulmuhaimen""  
}'

{  
"ok":true,  
"\_index":"test",  
"\_type":"test",  
"\_id":"uNWmgtr2TcqIBUgMmARnRg",  
"\_version":1  
}

$ curl -XGET localhost:9200/test/test/uNWmgtr2TcqIBUgMmARnRg

{  
"\_index":"test",  
"\_type":"test",  
"\_id":"uNWmgtr2TcqIBUgMmARnRg",  
"\_version":1,  
"exists":true,  
"\_source":{  
"newfield":""myname" : "Abdulmuhaimen""  
}  
}

And then running the result through PHP's json\_decode():

array (  
'\_index' =\> 'test',  
'\_type' =\> 'test',  
'\_id' =\> 'uNWmgtr2TcqIBUgMmARnRg',  
'\_version' =\> 1,  
'exists' =\> true,  
'\_source' =\>  
array (  
'newfield' =\> '"myname" : "Abdulmuhaimen"',  
),  
)

-Zach

On Monday, February 25, 2013 7:46:19 AM UTC-5, Abdelmuhaimen Mohamed wrote:

> Hi all
> 
> I want to index a string like the following (' "myname" : "Abdulmuhaimen"  
> '), which contains the special characters " and :, when i escape them using  
> , the \ is retrieved as well when geting back the text from the  
> elasticsearch (i.e. I index the text like "myname":"Abdulmuhaimen" and  
> get the same when retrieving it including the escape character). I want to  
> index such text and get back "myname" : "Abdulmuhaimen" when searching for  
> it without the escape character. Any help is appreciated.
> 
> Thanks in advance

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:49am UTC](https://discuss.elastic.co/t/i-want-to-index-elasticsearch-query/10879/3 "2017-07-06T02:49:41Z")

</div>


