# Search text wrapped in double quotes

**URL:** <https://discuss.elastic.co/t/search-text-wrapped-in-double-quotes/16202>\
**Category:** Elasticsearch\
**Created:** [March 6, 2014, 5:25pm UTC](https://discuss.elastic.co/t/search-text-wrapped-in-double-quotes/16202 "2014-03-06T17:25:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hector\_Sanchez\_Pajar](https://avatars.discourse-cdn.com/v4/letter/h/c77e96/32.png) [@Hector\_Sanchez\_Pajar](https://discuss.elastic.co/u/Hector_Sanchez_Pajar)\
**Post date:** [March 6, 2014, 5:25pm UTC](https://discuss.elastic.co/t/search-text-wrapped-in-double-quotes/16202/1 "2014-03-06T17:25:25Z")

</div>

Hello, I would like to know what is the best way to search for those hits  
which have some text wrapped in double quotes.

As an example, this is one of the items I have  
"\_index": "posts",  
"\_type": "post",  
"\_id": "2915129",  
"\_score": 1,  
"fields": {  
"text": [  
""Some times I'm not even sure I believe the things I  
can see."-John"  
]  
}

Right now I'm trying to use this query

POST /posts/\_search  
{  
"query": {  
"query\_string": {  
"query": "text:/(?:.\*("[^"]+")).+/"  
}  
}  
}

But I have the next error IllegalArgumentException[expected '"' at  
position 17

I have tried different solutions but with no success. I know it is tricky  
because of the double quotes since 1. they are reserved characters inside a  
regex, 2. They have to be escaped because is a json in the query, 3. Are  
the double quotes scape in the elasticsearch storage? 4. Should I look for  
" instead of just "

Actually I'm kind of lost and I think I have tried almost all  
possibilities. I was making this in a MySQL database before using this  
regex  
text.match(/"(?:[^"\]|\.)\*"/)  
but it doesn't work either.

Thanks for your help!

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ab192a94-736f-42e4-8eae-118d9656321d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ab192a94-736f-42e4-8eae-118d9656321d%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [March 6, 2014, 10:51pm UTC](https://discuss.elastic.co/t/search-text-wrapped-in-double-quotes/16202/2 "2014-03-06T22:51:03Z")

</div>

You'd probably need to first index that field as not analyzed, or something  
that does not strip the quotes. And then use the match query, like for  
example

{  
"query": {  
"match": {  
"text": ""hello world""  
}  
}  
}

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1d36345c-4b75-4ec6-91c3-ac60b75794ba%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1d36345c-4b75-4ec6-91c3-ac60b75794ba%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [March 7, 2014, 8:10am UTC](https://discuss.elastic.co/t/search-text-wrapped-in-double-quotes/16202/3 "2014-03-07T08:10:57Z")

</div>

Do not index quotation marks, do not use query\_string, do not use regexes.  
Just use match\_phrase to search phrases.

Jörg

On Thu, Mar 6, 2014 at 6:25 PM, Hector Sanchez-Pajares \<  
[hectorlovestodevelop@gmail.com](mailto:hectorlovestodevelop@gmail.com)\> wrote:

> Right now I'm trying to use this query
> 
> POST /posts/\_search  
> {  
> "query": {  
> "query\_string": {  
> "query": "text:/(?:.\*("[^"]+")).+/"  
> }  
> }  
> }

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEFjDgCL857TLkKV7hxoUpeZagbJw385ZhDS\_LAwRDS0A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEFjDgCL857TLkKV7hxoUpeZagbJw385ZhDS_LAwRDS0A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Konstantina.Lazarid](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@Konstantina.Lazarid](https://discuss.elastic.co/u/Konstantina.Lazarid)\
**Post date:** [January 21, 2016, 8:16pm UTC](https://discuss.elastic.co/t/search-text-wrapped-in-double-quotes/16202/4 "2016-01-21T20:16:48Z")

</div>

Hey Jorg,

how can you use match\_phrase to find all available phrases ? The goal is not to find specific phrases but text inside the quotation symbols. Could you be more specific please? I know that it's been a long time since the last answer in the topic, but I could use some help 🙂

This:  
.setQuery(QueryBuilders.matchPhraseQuery("body", ""(.\*?)""))  
returns nothing for me.

Thank you in advance for your time,

Konstantina

---

<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, 11:22pm UTC](https://discuss.elastic.co/t/search-text-wrapped-in-double-quotes/16202/5 "2017-07-05T23:22:24Z")

</div>


