Terms query not returning documents if string has spaces

Hi,

I have a scenario where i need to get documents related to multiple keywords.
here's the query:

{
"query":{
"filtered": {
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"should" : [
{ "terms" : {"allTags" : ["woodland shoes"]}}
]
}
}
}
},
"filter" : {
"bool" : {
"should" : [
{ "terms" : {"allTags" : ["amazon", "snapdeal" ]}}
]
}
}
}
}
}

in the mapping for allTags i have used my own analyzer with white space tokenizer also still
this doesn't return any documents, however

{
"query":{
"filtered": {
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"should" : [
{ "terms" : {"allTags" : ["woodlandshoes"]}}
]
}
}
}
},
"filter" : {
"bool" : {
"should" : [
{ "terms" : {"allTags" : ["amazon","snapdeal"]}}
]
}
}
}
}
}

returns documents.

Can any explain me why its behaving differently.

This is due to the fact that the terms aggregation does not apply analysis. You need to use the match query if you want analysis to be applied.

You can also use terms query with custom analyzer e.g. keyword.

Hi,

thanks @jpountz  for the reply. i have used match query and its working