Unable to escape special characters for a query

Hi all!

Sorry if this has been covered. I tried to do my searching first.

I have the query:

{"query":{"bool":{"must":[{"term":{"SID":"3962"}},{"term":{"BI":"True"}},{"query_string":{"default_field":"TA","query":"order-staging-541"}},{"term":{"TY":"2"}}]}}}

TA is a string field but when I search on it my query will also return any
results that look like the TA contents with other special characters.

So, for example, "order-staging-541" also matches "order staging-541" and
"order(staging-541".

I realize these are special characters but when I try to escape them as
such:

{"query":{"bool":{"must":[{"term":{"SID":"3962"}},{"term":{"BI":"True"}},{"query_string":{"default_field":"TA","query":"order-staging-541"}},{"term":{"TY":"2"}}]}}}

It throws a syntax error. I am trying to follow the Lucene special
characters escaping protocol laid out here
http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html at
the bottom but I'm still receiving syntax errors.

Any help would be greatly appreciated!!

Funny enough I just queried on t-mobile and it seems to work:
{"query":{"query_string":{"default_field":"text","query":"t\-mobile"}}}

The reason is because json also uses escape characters. Combined with your link I guess this is correct.

Kind regards,
Stefan.

By default, string fields are analyzed in elasticasearch. It means that
"order-staging-541" is indexed as 3 terms "order", "staging" and "541". You
query is also analyzed, and it's also converted into 3 terms "order",
"staging" and "541" no matter which special characters are in between.
That's why they are matching. If you want to search this field exactly as
it is, you should reindex it as "index":"not_analyzed".

On Monday, April 9, 2012 4:40:23 PM UTC-4, JP Toto wrote:

Hi all!

Sorry if this has been covered. I tried to do my searching first.

I have the query:

{"query":{"bool":{"must":[{"term":{"SID":"3962"}},{"term":{"BI":"True"}},{"query_string":{"default_field":"TA","query":"order-staging-541"}},{"term":{"TY":"2"}}]}}}

TA is a string field but when I search on it my query will also return any
results that look like the TA contents with other special characters.

So, for example, "order-staging-541" also matches "order staging-541" and
"order(staging-541".

I realize these are special characters but when I try to escape them as
such:

{"query":{"bool":{"must":[{"term":{"SID":"3962"}},{"term":{"BI":"True"}},{"query_string":{"default_field":"TA","query":"order-staging-541"}},{"term":{"TY":"2"}}]}}}

It throws a syntax error. I am trying to follow the Lucene special
characters escaping protocol laid out here
Apache Lucene - Query Parser Syntax at
the bottom but I'm still receiving syntax errors.

Any help would be greatly appreciated!!

Thanks, Igor! I came to that realization today. Got it fixed. I appreciate
the feedback :slight_smile:

On Tue, Apr 10, 2012 at 4:28 PM, Igor Motov imotov@gmail.com wrote:

By default, string fields are analyzed in elasticasearch. It means that
"order-staging-541" is indexed as 3 terms "order", "staging" and "541". You
query is also analyzed, and it's also converted into 3 terms "order",
"staging" and "541" no matter which special characters are in between.
That's why they are matching. If you want to search this field exactly as
it is, you should reindex it as "index":"not_analyzed".

On Monday, April 9, 2012 4:40:23 PM UTC-4, JP Toto wrote:

Hi all!

Sorry if this has been covered. I tried to do my searching first.

I have the query:

{"query":{"bool":{"must":[{"term":{"SID":"3962"}},{"term":
{"BI":"True"}},{"query_string":{"default_field":"TA","query"
:"order-staging-541"}},{"term"**:{"TY":"2"}}]}}}

TA is a string field but when I search on it my query will also return
any results that look like the TA contents with other special characters.

So, for example, "order-staging-541" also matches "order staging-541" and
"order(staging-541".

I realize these are special characters but when I try to escape them as
such:

{"query":{"bool":{"must":[{"term":{"SID":"3962"}},{"term":
{"BI":"True"}},{"query_string":{"default_field":"TA","query"
:"order-staging-541"}},{"**term":{"TY":"2"}}]}}}

It throws a syntax error. I am trying to follow the Lucene special
characters escaping protocol laid out here http://lucene.apache.org/**
core/old_versioned_docs/**versions/3_0_0/**queryparsersyntax.htmlhttp://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html at
the bottom but I'm still receiving syntax errors.

Any help would be greatly appreciated!!

--
JP Toto | james.p.toto@gmail.com | JP Toto | about.me