# Query\_string query, forward slash, how to explained?

**URL:** <https://discuss.elastic.co/t/query-string-query-forward-slash-how-to-explained/16637>\
**Category:** Elasticsearch\
**Created:** [March 27, 2014, 10:56am UTC](https://discuss.elastic.co/t/query-string-query-forward-slash-how-to-explained/16637 "2014-03-27T10:56:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Ji](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@Ivan\_Ji](https://discuss.elastic.co/u/Ivan_Ji)\
**Post date:** [March 27, 2014, 10:56am UTC](https://discuss.elastic.co/t/query-string-query-forward-slash-how-to-explained/16637/1 "2014-03-27T10:56:48Z")

</div>

Hi, all

Assume I have the document:

{

> ```
> "id": "/Users/jason/Documents/nose/DS_Store",
> "name": "danny",
> "language": "",
> "created": "2014-03-26T14:40:17Z",
> 
> ```
> 
> }

And I want to use query\_string query to find the "id" field with the exact  
value "/Users/jason/Documents/nose/DS\_Store"

The following command cannot find the above document:

{ "query":

> ```
> { "query_string":  
> { "query": "id:\\/Users\\/jason\\/Documents\\/nose\\/DS_Store"}
> }
> 
> ```
> 
> }

The _index\_analyzer_ of "id" field include the tokenizer "_path\_hierarchy_"  
and no filter. The _search\_analyzer_ of it is _standard_.

Are there any possible reason of it ??

BTW, I can use term query to find the document by using:

{ "query":  
{ "term":  
{ "id": "/Users/jason/Documents/nose/DS\_Store"}  
}  
}

So I think there might exist something in the query\_string query.

And are there any ways to know what operations does a query\_string query  
rewrite into?

Ideas?

Ivan

--  
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/85f49c48-f2a7-4b32-8e01-e01b59bb0624%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/85f49c48-f2a7-4b32-8e01-e01b59bb0624%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 27, 2014, 1:34pm UTC](https://discuss.elastic.co/t/query-string-query-forward-slash-how-to-explained/16637/2 "2014-03-27T13:34:39Z")

</div>

The term query is really what you want, but if you need the query\_string  
query, you can always override the search analyzer at query time:

{  
"query": {  
"query\_string": {  
"query": "id:\/Users\/jason\/Documents\/nose\/DS\_Store",  
"analyzer": "\<your\_index\_analyzer\_name\>"  
}  
}  
}

--  
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/c7ec1d09-82d1-4328-8c0d-a72a445c1c15%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7ec1d09-82d1-4328-8c0d-a72a445c1c15%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan\_Ji](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@Ivan\_Ji](https://discuss.elastic.co/u/Ivan_Ji)\
**Post date:** [March 27, 2014, 2:58pm UTC](https://discuss.elastic.co/t/query-string-query-forward-slash-how-to-explained/16637/3 "2014-03-27T14:58:49Z")

</div>

Hi Binh,

The search analyzer is assigned in the schema. So in theory, it can find  
the document, right?

So do you mean the search analyzer cannot be applied automatically in this  
case ? But I had make sure some other case will do apply the search  
analyzer.

cheers,

Ivan

Binh Ly於 2014年3月27日星期四UTC+8下午9時34分39秒寫道：

> The term query is really what you want, but if you need the query\_string  
> query, you can always override the search analyzer at query time:
> 
> {  
> "query": {  
> "query\_string": {  
> "query": "id:\/Users\/jason\/Documents\/nose\/DS\_Store",  
> "analyzer": "\<your\_index\_analyzer\_name\>"  
> }  
> }  
> }

--  
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/047a9c18-f166-4268-9af8-e3642bc0c598%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/047a9c18-f166-4268-9af8-e3642bc0c598%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 27, 2014, 3:24pm UTC](https://discuss.elastic.co/t/query-string-query-forward-slash-how-to-explained/16637/4 "2014-03-27T15:24:34Z")

</div>

Since your search\_analyzer is standard, it will tokenize your query string  
as standard (i.e. it will break it down), then it will match it against the  
path\_hierarchy tokens in the index which will not match. Since you indexed  
as path\_hierarchy and you want to search using an exact match, then you can  
either use terms, or use the same exact analyzer (path\_hierarchy) at query  
time.

You can always do a bool query with the term part in 1 clause, and the  
query\_string part in another clause if that's what you need.

--  
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/016bf83e-7e2c-4900-9aa1-965b187b8060%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/016bf83e-7e2c-4900-9aa1-965b187b8060%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan\_Ji](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@Ivan\_Ji](https://discuss.elastic.co/u/Ivan_Ji)\
**Post date:** [March 27, 2014, 3:36pm UTC](https://discuss.elastic.co/t/query-string-query-forward-slash-how-to-explained/16637/5 "2014-03-27T15:36:56Z")

</div>

Hi, Binh

I got it.

I did not notice the standard analyzer will also split "/". Thanks a lot.

Binh Ly於 2014年3月27日星期四UTC+8下午11時24分34秒寫道：

> Since your search\_analyzer is standard, it will tokenize your query string  
> as standard (i.e. it will break it down), then it will match it against the  
> path\_hierarchy tokens in the index which will not match. Since you indexed  
> as path\_hierarchy and you want to search using an exact match, then you can  
> either use terms, or use the same exact analyzer (path\_hierarchy) at query  
> time.
> 
> You can always do a bool query with the term part in 1 clause, and the  
> query\_string part in another clause if that's what you need.

--  
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/2b24274f-2cf6-4c47-876f-6d8c73542833%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2b24274f-2cf6-4c47-876f-6d8c73542833%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:40am UTC](https://discuss.elastic.co/t/query-string-query-forward-slash-how-to-explained/16637/6 "2017-07-06T01:40:08Z")

</div>


