Escapting special character during search is not working for not_analyzed field

Hi All,

Please excuse if it is already asked.

I am facing a weird situation of search not returning any hits, even on
escaping the special characters during search. The search field is
not_analyzed.

This is how data is indexed in the cluster.

{
"took":516,
"timed_out":false,
"_shards":{
"total":1,
"successful":1,
"failed":0
},
"hits":{
"total":2,
"max_score":1.0,
"hits":[
{
"_index":"moreovercontact",
"_type":"moreovercontact",
"_id":"1322",
"_score":1.0,
"_source":{
"contactid":"1322",
"contactname":"Wanda "Blueberry Freak" C.",
"email":"",
"sourceid":"4715"
}
}
]
}
}

The search request builder I used to pick data from the index is:

{
"from":0,
"size":10,
"query":{
"bool":{
"should":{
"bool":{
"must":[
{
"query_string":{
"query":"Wanda "Blueberry Freak" C.",
"fields":[
"contactname.sort"
],
"use_dis_max":true
}
},
{
"query_string":{
"query":"4715",
"fields":[
"sourceid"
],
"use_dis_max":true
}
}
]
}
}
}
},
"explain":true,
"fields":[
"contactid",
"contactname"
]
}

Hope I have escaped the special character in the query string in right
way. Let me know if I need to provide any more information regarding this

Could anybody help me on this problem?

Thank You!
Manoj

The query_string query is parsing the query string. It uses spaces to split
the query string into clauses and as a result your query is getting
translated into something like:

contactname.sort:Wanda OR contactname.sort:"Blueberry Freak" 

OR contactname.sort:C.

To force query_string to treat your query as a single term, you need
another pair of quotes:

"query":"\"Wanda \\\"Blueberry Freak\\\" C.\"",

However, considering that your field is not analyzed, it would be more
efficient to simply use "term" query instead of query_string.

On Friday, July 27, 2012 9:17:50 AM UTC-4, Manoj wrote:

Hi All,

Please excuse if it is already asked.

I am facing a weird situation of search not returning any hits, even on
escaping the special characters during search. The search field is
not_analyzed.

This is how data is indexed in the cluster.

{
"took":516,
"timed_out":false,
"_shards":{
"total":1,
"successful":1,
"failed":0
},
"hits":{
"total":2,
"max_score":1.0,
"hits":[
{
"_index":"moreovercontact",
"_type":"moreovercontact",
"_id":"1322",
"_score":1.0,
"_source":{
"contactid":"1322",
"contactname":"Wanda "Blueberry Freak" C.",
"email":"",
"sourceid":"4715"
}
}
]
}
}

The search request builder I used to pick data from the index is:

{
"from":0,
"size":10,
"query":{
"bool":{
"should":{
"bool":{
"must":[
{
"query_string":{
"query":"Wanda "Blueberry Freak" C.",
"fields":[
"contactname.sort"
],
"use_dis_max":true
}
},
{
"query_string":{
"query":"4715",
"fields":[
"sourceid"
],
"use_dis_max":true
}
}
]
}
}
}
},
"explain":true,
"fields":[
"contactid",
"contactname"
]
}

Hope I have escaped the special character in the query string in right
way. Let me know if I need to provide any more information regarding this

Could anybody help me on this problem?

Thank You!
Manoj