Check if field exists in a nested object


(Maximilian S.) #1

In my database I always have an object "foo", and I want the results where
the field "bar" exists. Independendtly of its value ("baz" or something
else).

{
"foo":{
"bar":"baz"
}
}

Which query and which filter do I need?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Ivan Brusic) #2

Perhaps the exists filter will work in your situation:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html

Cheers,

Ivan

On Fri, Oct 4, 2013 at 5:04 AM, Maximilian S. <
maximilian.schlederer@gmail.com> wrote:

In my database I always have an object "foo", and I want the results where
the field "bar" exists. Independendtly of its value ("baz" or something
else).

{
"foo":{
"bar":"baz"
}
}

Which query and which filter do I need?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Maximilian S.) #3

Problem is that I don't know how to apply this filter to my nested
object... And which query should I use?

Am Freitag, 4. Oktober 2013 20:23:41 UTC+2 schrieb Ivan Brusic:

Perhaps the exists filter will work in your situation:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html

Cheers,

Ivan

On Fri, Oct 4, 2013 at 5:04 AM, Maximilian S. <maximilian...@gmail.com<javascript:>

wrote:

In my database I always have an object "foo", and I want the results
where the field "bar" exists. Independendtly of its value ("baz" or
something else).

{
"foo":{
"bar":"baz"
}
}

Which query and which filter do I need?

--
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 elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Ivan Brusic) #4

You can use a match all query.

curl -X GET "http://localhost:9200/products/product/_search?pretty=true" -d
'
{
"query" : {
"nested" : {
"path" : "foo",
"query" : { "match_all" : { } },
"filter" : {
"exists" : { "field" : "foo.bar" }
}
}
},
"size" : 0
}
'

You can also turn this into a filtered query depending on your use case.

Cheers,

Ivan

On Fri, Oct 4, 2013 at 1:03 PM, Maximilian S. <
maximilian.schlederer@gmail.com> wrote:

Problem is that I don't know how to apply this filter to my nested
object... And which query should I use?

Am Freitag, 4. Oktober 2013 20:23:41 UTC+2 schrieb Ivan Brusic:

Perhaps the exists filter will work in your situation:

http://www.elasticsearch.org/guide/en/elasticsearch/
reference/current/query-dsl-**exists-filter.htmlhttp://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html

Cheers,

Ivan

On Fri, Oct 4, 2013 at 5:04 AM, Maximilian S. <maximilian...@gmail.**com>wrote:

In my database I always have an object "foo", and I want the results
where the field "bar" exists. Independendtly of its value ("baz" or
something else).

{
"foo":{
"bar":"baz"
}
}

Which query and which filter do I need?

--
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 elasticsearc...@**googlegroups.com.

For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #5