Correct way to apply multiple nested filters

Hi all,

I'm having some difficulties running queries with multiple nested filters.
Consider the following mapping:

{
"template" : "products",
"mappings" : {
"Product" : {
"dynamic" : "false",
"properties" : {
"id" : {
"type" : "long"
},
"name" : {
"type" : "string",
"analyzer" : "standard"
},
"reviews" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"positive" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"reviewCount" : {
"type" : "integer"
},
"keywords" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"id" : {
"type" : "long"
},
"name" : {
"type" : "string",
"analyzer" : "standard"
},
"score": {
"type": "double"
},
"frequency": {
"type": "integer"
}
}
}
}
},
"negative" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"reviewCount" : {
"type" : "integer"
},
"keywords" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"id" : {
"type" : "long"
},
"name" : {
"type" : "string",
"analyzer" : "standard"
},
"score": {
"type": "double"
},
"frequency": {
"type": "integer"
}
}
}
}
}
}
}
}
}
}
}

Running the following query:

NestedFilterBuilder idFilter = nestedFilter( "reviews.positive.keywords",
filteredQuery( matchAllQuery(), termFilter( "reviews.positive.keywords.id",
id ) ) );
NestedFilterBuilder scoreFilter = nestedFilter(
"reviews.positive.keywords", filteredQuery( matchAllQuery(), rangeFilter(
"reviews.positive.keywords.score" ).from( score ).includeLower( true ) ) );

RangeFilterBuilder productScoreFilter = rangeFilter( "score" ).from(
productScore ).includeLower( true );

SearchResponse searchResponse = esClient.prepareSearch( "products" ).
setQuery( filteredQuery( matchAllQuery(), andFilter( productScoreFilter,
idFilter, scoreFilter ) ) ).
setSize( 40000 ).
get();

The returned hits contain results with wrong score, i.e. score lower than
what configured at scoreFilter. Seems like other filters are working
perfect. Am I using the wrong way to apply multiple nested filters?

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/cb007c0e-0aa2-4aec-b88c-db53407d114e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

The following works, although I'm not sure why the previous query didn't..

AndFilterBuilder keywordFilter = andFilter( termFilter(
"reviews.positive.keywords.id", id ), rangeFilter(
"reviews.positive.keywords.score" ).from( score ).includeLower( true ) );

NestedFilterBuilder nestedKeywordFilter = nestedFilter(
"reviews.positive.keywords", filteredQuery( matchAllQuery(), keywordFilter
) );

RangeFilterBuilder productScoreFilter = rangeFilter( "score" ).from(
productScore ).includeLower( true );

SearchResponse searchResponse = esClient.prepareSearch( "products" ).
setQuery( filteredQuery( matchAllQuery(), andFilter( productScoreFilter,
nestedKeywordFilter ) ) ).
setSize( 40000 ).
get();

On Sunday, April 19, 2015 at 12:21:04 PM UTC+3, barak wrote:

Hi all,

I'm having some difficulties running queries with multiple nested filters.
Consider the following mapping:

{
"template" : "products",
"mappings" : {
"Product" : {
"dynamic" : "false",
"properties" : {
"id" : {
"type" : "long"
},
"name" : {
"type" : "string",
"analyzer" : "standard"
},
"reviews" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"positive" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"reviewCount" : {
"type" : "integer"
},
"keywords" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"id" : {
"type" : "long"
},
"name" : {
"type" : "string",
"analyzer" : "standard"
},
"score": {
"type": "double"
},
"frequency": {
"type": "integer"
}
}
}
}
},
"negative" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"reviewCount" : {
"type" : "integer"
},
"keywords" : {
"type" : "nested",
"dynamic" : "false",
"properties" : {
"id" : {
"type" : "long"
},
"name" : {
"type" : "string",
"analyzer" : "standard"
},
"score": {
"type": "double"
},
"frequency": {
"type": "integer"
}
}
}
}
}
}
}
}
}
}
}

Running the following query:

NestedFilterBuilder idFilter = nestedFilter( "reviews.positive.keywords",
filteredQuery( matchAllQuery(), termFilter( "reviews.positive.keywords.id",
id ) ) );
NestedFilterBuilder scoreFilter = nestedFilter(
"reviews.positive.keywords", filteredQuery( matchAllQuery(), rangeFilter(
"reviews.positive.keywords.score" ).from( score ).includeLower( true ) ) );

RangeFilterBuilder productScoreFilter = rangeFilter( "score" ).from(
productScore ).includeLower( true );

SearchResponse searchResponse = esClient.prepareSearch( "products" ).
setQuery( filteredQuery( matchAllQuery(), andFilter( productScoreFilter,
idFilter, scoreFilter ) ) ).
setSize( 40000 ).
get();

The returned hits contain results with wrong score, i.e. score lower than
what configured at scoreFilter. Seems like other filters are working
perfect. Am I using the wrong way to apply multiple nested filters?

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ede31922-dadc-4003-bd04-650cb3340371%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.