Exists filter not working

Hi guys

My exists filter is not working for the array stucture. The query is as
follows:

{
"query": {
"filtered": {
"query": {
"term": {
"subtype": {
"value": "izapregistereduser",
"boost": 1
}
}
},
"filter": {
"exists": {
"field": "posts"
}
}
}
}
}
Here the posts is a nested array stucture,but if i run the following query,
its giving the results:

{
"query": {
"filtered": {
"query": {
"term": {
"subtype": {
"value": "izapregistereduser",
"boost": 1
}
}
},
"filter": {
"exists": {
"field": "guid"
}
}
}
}
}

Here the guid can be a numeric or string value

Can anyone tell me the reason and solution plz???

What si posts? Is it an actual field that gets indexed? Can you gist an example of the data you index?

On Tuesday, January 31, 2012 at 2:59 PM, Narinder Kaur wrote:

Hi guys

My exists filter is not working for the array stucture. The query is as follows:

{
"query": {
"filtered": {
"query": {
"term": {
"subtype": {
"value": "izapregistereduser",
"boost": 1
}
}
},
"filter": {
"exists": {
"field": "posts"
}
}
}
}
}
Here the posts is a nested array stucture,but if i run the following query, its giving the results:

{
"query": {
"filtered": {
"query": {
"term": {
"subtype": {
"value": "izapregistereduser",
"boost": 1
}
}
},
"filter": {
"exists": {
"field": "guid"
}
}
}
}
}

Here the guid can be a numeric or string value

Can anyone tell me the reason and solution plz???

       Its an nested array structure, that has some ids and related 

attributes to those ids. and I wanted to get only those documents which has
this posts or non-empty posts . You can have an idea about its structure
from the following example.

posts: [

{
    id: 195098
    can_reply: true
    owner_guid: 194988
    pushed_owner_guid: 57
    relations: null
}
{
    id: 195097
    can_reply: true
    owner_guid: 194988
    relations: [
        friend_of
        all
    ]
}
{
    id: 195096
    can_reply: true
    owner_guid: 194988
    relations: [
        friend_of
        all
    ]
}
{
    id: 195095
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195084
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195083
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195082
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195072
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195071
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195070
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195069
    can_reply: true
    owner_guid: 194988
    relations: [
        friend_of
        all
    ]
}
{
    id: 195059
    can_reply: true
    owner_guid: 194988
    pushed_owner_guid: 57
    relations: null
}
{
    id: null
    can_reply: true
    owner_guid: 194988
    pushed_owner_guid: 57
    relations: null
}
{
    id: null
    can_reply: true
    owner_guid: 194988
    pushed_owner_guid: 57
    relations: null
}
{
    id: 195034
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195033
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195032
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195031
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195028
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195027
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195009
    can_reply: true
    owner_guid: 194988
    relations: [
        all
        follower_of
    ]
}
{
    id: 195008
    can_reply: true
    owner_guid: 194988
    relations: [
        all
        follower_of
    ]
}

]

You can only do exists on a specific actual "core" field that has data, not on a json object, for example, on posts.id

On Wednesday, February 1, 2012 at 8:01 AM, Narinder Kaur wrote:

       Its an nested array structure, that has some ids and related attributes to those ids. and I wanted to get only those documents which has this posts or non-empty posts . You can have an idea about its structure from the following example.

posts: [

{
    id: 195098
    can_reply: true
    owner_guid: 194988
    pushed_owner_guid: 57
    relations: null
}
{
    id: 195097
    can_reply: true
    owner_guid: 194988
    relations: [
        friend_of
        all
    ]
}
{
    id: 195096
    can_reply: true
    owner_guid: 194988
    relations: [
        friend_of
        all
    ]
}
{
    id: 195095
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195084
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195083
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195082
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195072
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195071
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195070
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195069
    can_reply: true
    owner_guid: 194988
    relations: [
        friend_of
        all
    ]
}
{
    id: 195059
    can_reply: true
    owner_guid: 194988
    pushed_owner_guid: 57
    relations: null
}
{
    id: null
    can_reply: true
    owner_guid: 194988
    pushed_owner_guid: 57
    relations: null
}
{
    id: null
    can_reply: true
    owner_guid: 194988
    pushed_owner_guid: 57
    relations: null
}
{
    id: 195034
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195033
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195032
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195031
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195028
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195027
    can_reply: true
    owner_guid: 57
    relations: [ ]
}
{
    id: 195009
    can_reply: true
    owner_guid: 194988
    relations: [
        all
        follower_of
    ]
}
{
    id: 195008
    can_reply: true
    owner_guid: 194988
    relations: [
        all
        follower_of
    ]
}

]

Thanks for the solution, its working now

I don't mean to hijack this thread, but I think I'm trying to achieve the
same as the OP, but I have no alternatives other than to check whether or
not a json object exists. For example the structure:

[
{
"User" : "Marcus",
"Content" : {
"Content" : "This is a post",
"Title" : "The title of this post"
},
"Media" : {
"Header" : "http://.../images/one.jpg"
}
},
{
"User" : "Marcus",
"Content" : {
"Content" : "This is another post, but without a header",
"Title" : "The title of this other post"
}
}
]

These objects are representative of the problem, but are not my structures.
I need to be able to find all documents with a "Media" object.

As long as I can retrieve the objects in the above structure I am open to
adding an array of the keys present as long as I can remove it before
retrieval.

One workaround I was pondering was to use the filter on one of the core
fields in the "Media" object, but the keys are subject to change so there
isn't a single key which is present for all "Media" objects.

Is there a technical reason why the exists filter isn't implemented on
objects?