Exist filter also matching on nested fields

I'm trying to filter documents that have a particular field at the top
level. Like for example:

{
"group_id":"xxx"
}

so I wrote the following query:

GET inbot_users/usercontact/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"exists": {
"field": "group_id"
}
}
}
}
}

But now my problem is that it is also returning documents with a nested
group_id property:

{
"nested":{
"group_id":"xxx"
}
}

In this case I wouldn't expect a match because I specified "group_id" and
not "nested.group_id".

How can I make it filter just documents that have the field at the top
level like is clearly the intention here?

--
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/d2019aac-77e8-43ce-a7c3-2afb4a8403e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Jilles,

I just tried, but wasn't able to reproduce this behavior. In my test ES
only returned the correct document. I created a gist for that:

I tried it using ES 1.4.1. Which version are you using? Does my gist
work for you? I noticed that it doesn't matter whether or not it is a
nested document.

Best regards,
Hannes

On 10.02.2015 15:52, Jilles van Gurp wrote:

I'm trying to filter documents that have a particular field at the top
level. Like for example:

{
"group_id":"xxx"
}

so I wrote the following query:

GET inbot_users/usercontact/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"exists": {
"field": "group_id"
}
}
}
}
}

But now my problem is that it is also returning documents with a nested
group_id property:

{
"nested":{
"group_id":"xxx"
}
}

In this case I wouldn't expect a match because I specified "group_id" and
not "nested.group_id".

How can I make it filter just documents that have the field at the top
level like is clearly the intention here?

--
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/54DA2675.1080401%40hkorte.com.
For more options, visit https://groups.google.com/d/optout.

Thanks, I've been trying to reproduce this myself with a minimal
example but so far it seems specific to our index in production.

Our mapping there is kind of large (over 7000 lines:
es mapping · GitHub) with lots of
auto generated fields, so that doesn't help. As you can see, the group_id
field comes back in a few places.

We use parent child relations, default templates, etc. So far all the
mapping variations I've tried on my minimal example fail to reproduce the
problem. Obviously it somehow is related to my mapping but can't spot how
or why.

I'll keep on digging to see if I can find anything.

Jilles

On Tuesday, February 10, 2015 at 4:40:54 PM UTC+1, Hannes Korte wrote:

Hi Jilles,

I just tried, but wasn't able to reproduce this behavior. In my test ES
only returned the correct document. I created a gist for that:
An Elasticsearch gist for the thread "exist filter also matching on nested fields": https://groups.google.com/forum/#!topic/elasticsearch/8R9XgVkCZIU · GitHub

I tried it using ES 1.4.1. Which version are you using? Does my gist
work for you? I noticed that it doesn't matter whether or not it is a
nested document.

Best regards,
Hannes

On 10.02.2015 15:52, Jilles van Gurp wrote:

I'm trying to filter documents that have a particular field at the top
level. Like for example:

{
"group_id":"xxx"
}

so I wrote the following query:

GET inbot_users/usercontact/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"exists": {
"field": "group_id"
}
}
}
}
}

But now my problem is that it is also returning documents with a nested
group_id property:

{
"nested":{
"group_id":"xxx"
}
}

In this case I wouldn't expect a match because I specified "group_id"
and
not "nested.group_id".

How can I make it filter just documents that have the field at the top
level like is clearly the intention here?

--
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/a90712c5-c916-4a37-92c9-6778eeed645f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.