In my query, I specify a "country"+ a filter query, and need to get the count of each distinct "name".
If I'd do terms aggregation on the "name" field, I would get the count of _docs each name appears in. but I need the count of name at all docs for a given country.
I need the following query to return only names for 'england'
It's possible, but you'll need to use the nested datatypes instead. Regular json objects (like your example) are "flattened" internally and lose their relationship. E.g. internally that data will be stored as:
The nested data type internally uses a different storage mechanism to keep the relations between items in an object, so that you can run queries/aggregrations like you requested.
Thank you!
Yes, I did tried that eventually, but since I have more then 200k distinct nested terms, the nested aggregations had too many buckets.
The solution I found is to store everything flat with string prefixes, and use script regexp to query subsets of the tree :
Yeah agreed, 200k nested objects would be too many
I'd probably try to restructure things so that each doc is one of the distinct pairs and they are all related by some kind of identifier. Basically denormalize each relation to it's own document. ES tends to be easier to work with when you're more denormalized... the relational tools are only rough approximations of real RDBMs functionality.
Yes, my case is problematic since I have large documents (2MB each),
Each document contain a list of all events occurred on a single client per week.
I tried to store it flat (_doc = event), but i cannot make queries such as
"for a given group of clients, find significant event id's".
Further reducing the time window will break relations between events.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.