Query nested objects gives incorrect results


(Ben Ryan) #1

Hi,
I have the following mapping for an index:

{

"jorumindex": {
    "oerdocument": {
        "dynamic_templates": [
            {
                "default": {
                    "mapping": {
                        "type": "multi_field",
                        "fields": {
                            "exact": {
                                "index": "not_analyzed",
                                "store": "yes",
                                "type": "{dynamic_type}"
                            },
                            "{name}": {
                                "index": "analyzed",
                                "store": "no",
                                "analyzer": "standard",
                                "type": "{dynamic_type}"
                            }
                        }
                    },
                    "match": "*",
                    "match_mapping_type": "string"
                }
            }
        ],
        "properties": {
            "author": {
                "type": "multi_field",
                "fields": {
                    "author": {
                        "type": "string",
                        "analyzer": "standard"
                    },
                    "exact": {
                        "type": "string",
                        "index": "not_analyzed",
                        "store": true,
                        "omit_norms": true,
                        "index_options": "docs",
                        "include_in_all": false
                    }
                }
            },
            "statistics": {
                "type": "nested",
                "include_in_parent": true,
                "include_in_root": true,
                "properties": {
                    "event_type": {
                        "type": "string",
                        "index": "not_analyzed",
                        "omit_norms": true,
                        "index_options": "docs",
                        "include_in_all": false
                    },
                   
                    "time": {
                        "type": "date",
                        "format": "dateOptionalTime",
                        "include_in_all": false
                    }
                }
            },
            "subject": {
                "type": "multi_field",
                "fields": {
                    "subject": {
                        "type": "string",
                        "analyzer": "standard"
                    },
                    "exact": {
                        "type": "string",
                        "index": "not_analyzed",
                        "store": true,
                        "omit_norms": true,
                        "index_options": "docs",
                        "include_in_all": false
                    }
                }
            }
        }
    }
}

}

I am attempting to get a count from the nested statistics objects for a
time period with the following query:

q=statistics.event_type:"download" AND
statistics.time:[2013-09-04T00:00:00.000Z TO 2013-10-30T23:59:00.000Z]

This appears to return the count of documents that meet the criteria and
not the total count (I have taken this query straight from our SOLR
application).

Can anybody point me in the right direction to get the total count?

Regards,
Ben

--
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

Are you saying you are getting a count of the top-level documents, but you
want to get a count of the nested documents? Hopefully someone will correct
me if I am wrong, but I do not think that is possible. The queries execute
a join query in the background and only the top level documents are
returned. You can execute a facet on a nested field to get the correct
count of nested documents.

Cheers,

Ivan

On Tue, Nov 5, 2013 at 3:23 AM, Ben Ryan argaric@gmail.com wrote:

Hi,
I have the following mapping for an index:

{

"jorumindex": {
    "oerdocument": {
        "dynamic_templates": [
            {
                "default": {
                    "mapping": {
                        "type": "multi_field",
                        "fields": {
                            "exact": {
                                "index": "not_analyzed",
                                "store": "yes",
                                "type": "{dynamic_type}"
                            },
                            "{name}": {
                                "index": "analyzed",
                                "store": "no",
                                "analyzer": "standard",
                                "type": "{dynamic_type}"
                            }
                        }
                    },
                    "match": "*",
                    "match_mapping_type": "string"
                }
            }
        ],
        "properties": {
            "author": {
                "type": "multi_field",
                "fields": {
                    "author": {
                        "type": "string",
                        "analyzer": "standard"
                    },
                    "exact": {
                        "type": "string",
                        "index": "not_analyzed",
                        "store": true,
                        "omit_norms": true,
                        "index_options": "docs",
                        "include_in_all": false
                    }
                }
            },
            "statistics": {
                "type": "nested",
                "include_in_parent": true,
                "include_in_root": true,
                "properties": {
                    "event_type": {
                        "type": "string",
                        "index": "not_analyzed",
                        "omit_norms": true,
                        "index_options": "docs",
                        "include_in_all": false
                    },

                    "time": {
                        "type": "date",
                        "format": "dateOptionalTime",
                        "include_in_all": false
                    }
                }
            },
            "subject": {
                "type": "multi_field",
                "fields": {
                    "subject": {
                        "type": "string",
                        "analyzer": "standard"
                    },
                    "exact": {
                        "type": "string",
                        "index": "not_analyzed",
                        "store": true,
                        "omit_norms": true,
                        "index_options": "docs",
                        "include_in_all": false
                    }
                }
            }
        }
    }
}

}

I am attempting to get a count from the nested statistics objects for a
time period with the following query:

q=statistics.event_type:"download" AND
statistics.time:[2013-09-04T00:00:00.000Z TO 2013-10-30T23:59:00.000Z]

This appears to return the count of documents that meet the criteria and
not the total count (I have taken this query straight from our SOLR
application).

Can anybody point me in the right direction to get the total count?

Regards,
Ben

--
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) #3