Mulitiple or loop with range


(Thanigaivelan) #1

Hi,

I want to fetch the data by product id and rating I had used below code for it , but it is not working, when i removed the rating range the code working fine.

I f i add the rating filter, i am getting unwanted result, showing some other product id also.

{
"query": {
"bool": {
"should": [
{
"match": {
"pid": "TC0000362"
}
},
{
"match": {
"pid": "T0001999"
}
},
{
"match": {
"pid": "TC0000363"
}
},
{
"match": {
"pid": "TC0000538"
}
},
{
"match": {
"pid": "TC0000550"
}
},
{
"match": {
"pid": "TC0000551"
}
},
{
"match": {
"pid": "TC0000554"
}
}
],
"filter": {
"bool": {
"must": {
"range": {
"rating": {
"gte": 4.5
}
}
}
}
}
}
}
}

Please help me what mistake i am doing over here

Thanks

Thanigaivelan


(Yannick Welsch) #2

The reason is this (from the docs):

In a boolean query with no must or filter clauses, one or more should clauses must match a document.

This means that when you add a filter, ES does not require any should clause to match, they're only used to rank the results in that case. You can change this by explicitly setting "minimum_should_match" : 1


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.