Terms query not returning documents if string has spaces


(Ram Sailendra Varma Bhethalam) #1

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.


(Adrien Grand) #2

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.


(chintan visani) #3

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


(Ram Sailendra Varma Bhethalam) #4

Hi,

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

(system) #5