Problem with combined nested bool filters (nested key/value matching)

Hey Guys,

Seems like there is an issue with a combined bool filter with nested docs.

I have the following mapping:

{
"mappings": {
"test": {
"properties": {
"name": {
"type": "string",
"index": "not_analyzed"
},
"attributes": {
"type": "nested",
"properties": {
"name": {
"type": "string",
"index": "not_analyzed"
},
"stringValue": {
"type": "string",
"index": "not_analyzed"
},
"doubleValue": {
"type": "double"
}
}
}
}
}
}
}
And I index the following document in it:

{
"name": "John Stamos",
"attributes": [
{
"name": "Name",
"stringValue": "John"
},
{
"name": "Age",
"doubleValue": 34
}
]
}
If I run the following query, I get the correct result, which is the indexed document:

{
"query": {
"filtered": {
"filter": {
"nested": {
"path": "attributes",
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"term": {
"attributes.name": "Name"
}
},
{
"term": {
"attributes.stringValue": "John"
}
}
]
}
}
]
}
}
}
}
}
}
}
The query also works correctly if I filter by "Age". But if I combine two bool filters ("Name" and "Age"), then I don't get any results.

{
"query": {
"filtered": {
"filter": {
"nested": {
"path": "attributes",
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"term": {
"attributes.name": "Name"
}
},
{
"term": {
"attributes.stringValue": "John"
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"attributes.name": "Age"
}
},
{
"range": {
"attributes.doubleValue": {
"gt": 5
}
}
}
]
}
}
]
}
}
}
}
}
}
}

--
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/5E52EB8D-3FB3-41F3-9583-7493255AEE66%40venarc.com.
For more options, visit https://groups.google.com/d/optout.

I was able to get this to work. The problem was that I had to put the "bool" filter before the "nested" filter so now what I have is "bool" -> "nested" -> "bool".

On Aug 20, 2014, at 9:44 PM, Drew Kutcharian drew@venarc.com wrote:

Hey Guys,

Seems like there is an issue with a combined bool filter with nested docs.

I have the following mapping:

{
"mappings": {
"test": {
"properties": {
"name": {
"type": "string",
"index": "not_analyzed"
},
"attributes": {
"type": "nested",
"properties": {
"name": {
"type": "string",
"index": "not_analyzed"
},
"stringValue": {
"type": "string",
"index": "not_analyzed"
},
"doubleValue": {
"type": "double"
}
}
}
}
}
}
}
And I index the following document in it:

{
"name": "John Stamos",
"attributes": [
{
"name": "Name",
"stringValue": "John"
},
{
"name": "Age",
"doubleValue": 34
}
]
}
If I run the following query, I get the correct result, which is the indexed document:

{
"query": {
"filtered": {
"filter": {
"nested": {
"path": "attributes",
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"term": {
"attributes.name": "Name"
}
},
{
"term": {
"attributes.stringValue": "John"
}
}
]
}
}
]
}
}
}
}
}
}
}
The query also works correctly if I filter by "Age". But if I combine two bool filters ("Name" and "Age"), then I don't get any results.

{
"query": {
"filtered": {
"filter": {
"nested": {
"path": "attributes",
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"term": {
"attributes.name": "Name"
}
},
{
"term": {
"attributes.stringValue": "John"
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"attributes.name": "Age"
}
},
{
"range": {
"attributes.doubleValue": {
"gt": 5
}
}
}
]
}
}
]
}
}
}
}
}
}
}

--
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/5E52EB8D-3FB3-41F3-9583-7493255AEE66%40venarc.com.
For more options, visit https://groups.google.com/d/optout.

--
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/11D468C1-BC42-46BE-A163-1E328AF000CD%40venarc.com.
For more options, visit https://groups.google.com/d/optout.