Merge the results of two aggregations Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Show all Elasticsearch aggregation results/buckets and not just 10Elasticsearch Terms or Cardinality Aggregation - Order by number of distinct valueshow to return the count of unique documents by using elasticsearch aggregationHow to get the parent document in a nested top_hits aggregation?Insert aggregation results into an indexelasticsearch groovy No such property: ctx for classElasticsearch range bucket aggregation based on doc_countElasticsearch: aggregations and one-to-many relationshipElasticSearch calculate percentage for each bucket from totalHow to return actual value (not lowercase) when performing search with terms aggregation?
How do I find out the mythology and history of my Fortress?
Is multiple magic items in one inherently imbalanced?
What initially awakened the Balrog?
How to report t statistic from R
Can a Beast Master ranger change beast companions?
Why are vacuum tubes still used in amateur radios?
What is the home of the drow in Flanaess?
Why does 14 CFR have skipped subparts in my ASA 2019 FAR/AIM book?
Why weren't discrete x86 CPUs ever used in game hardware?
What is the meaning of 'breadth' in breadth first search?
Co-worker has annoying ringtone
Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?
Do wooden building fires get hotter than 600°C?
AppleTVs create a chatty alternate WiFi network
How can I prevent/balance waiting and turtling as a response to cooldown mechanics
How were pictures turned from film to a big picture in a picture frame before digital scanning?
Do I really need to have a message in a novel to appeal to readers?
Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?
How does Belgium enforce obligatory attendance in elections?
Amount of permutations on an NxNxN Rubik's Cube
How many time has Arya actually used Needle?
How to run automated tests after each commit?
Strange behavior of Object.defineProperty() in JavaScript
Electrolysis of water: Which equations to use? (IB Chem)
Merge the results of two aggregations
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Show all Elasticsearch aggregation results/buckets and not just 10Elasticsearch Terms or Cardinality Aggregation - Order by number of distinct valueshow to return the count of unique documents by using elasticsearch aggregationHow to get the parent document in a nested top_hits aggregation?Insert aggregation results into an indexelasticsearch groovy No such property: ctx for classElasticsearch range bucket aggregation based on doc_countElasticsearch: aggregations and one-to-many relationshipElasticSearch calculate percentage for each bucket from totalHow to return actual value (not lowercase) when performing search with terms aggregation?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have an Elasticsearch index with documents that have the following fields:
- author
- contributor
Each of these fields may contain multiple user IDs.
I want to perform an aggregation that counts the total number of documents related to each user (either as author or contributor).
I can query each aggregation separately, but how do I combine them? Here's my query:
GET documents/_search
"aggs":
"contributor":
"terms":
"field": "contributor"
,
"author":
"terms":
"field": "author"
Right now, I'm getting this result:
"aggregations":
"author":
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
"key": 2,
"doc_count": 10
,
"key": 1,
"doc_count": 7
,
"key": 5,
"doc_count": 3
]
,
"contributor":
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
"key": 5,
"doc_count": 1
]
But I'd like to have a single aggregation that returns the count of 4 documents for user 5.
add a comment |
I have an Elasticsearch index with documents that have the following fields:
- author
- contributor
Each of these fields may contain multiple user IDs.
I want to perform an aggregation that counts the total number of documents related to each user (either as author or contributor).
I can query each aggregation separately, but how do I combine them? Here's my query:
GET documents/_search
"aggs":
"contributor":
"terms":
"field": "contributor"
,
"author":
"terms":
"field": "author"
Right now, I'm getting this result:
"aggregations":
"author":
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
"key": 2,
"doc_count": 10
,
"key": 1,
"doc_count": 7
,
"key": 5,
"doc_count": 3
]
,
"contributor":
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
"key": 5,
"doc_count": 1
]
But I'd like to have a single aggregation that returns the count of 4 documents for user 5.
add a comment |
I have an Elasticsearch index with documents that have the following fields:
- author
- contributor
Each of these fields may contain multiple user IDs.
I want to perform an aggregation that counts the total number of documents related to each user (either as author or contributor).
I can query each aggregation separately, but how do I combine them? Here's my query:
GET documents/_search
"aggs":
"contributor":
"terms":
"field": "contributor"
,
"author":
"terms":
"field": "author"
Right now, I'm getting this result:
"aggregations":
"author":
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
"key": 2,
"doc_count": 10
,
"key": 1,
"doc_count": 7
,
"key": 5,
"doc_count": 3
]
,
"contributor":
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
"key": 5,
"doc_count": 1
]
But I'd like to have a single aggregation that returns the count of 4 documents for user 5.
I have an Elasticsearch index with documents that have the following fields:
- author
- contributor
Each of these fields may contain multiple user IDs.
I want to perform an aggregation that counts the total number of documents related to each user (either as author or contributor).
I can query each aggregation separately, but how do I combine them? Here's my query:
GET documents/_search
"aggs":
"contributor":
"terms":
"field": "contributor"
,
"author":
"terms":
"field": "author"
Right now, I'm getting this result:
"aggregations":
"author":
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
"key": 2,
"doc_count": 10
,
"key": 1,
"doc_count": 7
,
"key": 5,
"doc_count": 3
]
,
"contributor":
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
"key": 5,
"doc_count": 1
]
But I'd like to have a single aggregation that returns the count of 4 documents for user 5.
asked Mar 22 at 10:54
tomorrow__tomorrow__
2502512
2502512
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Well if you can update your mappings and add a field this should work. Please not it could be really slow (agg on string are slow and shouldnot be over used). Note if author = contributor in the same doc the agg will wont count 2 occurance (good news).
"mappings":
"test":
"properties":
"contributor":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author_and_contributor":
"type": "string",
"fielddata": true
"size": 0,
"aggs":
"author_contrib_agg":
"terms":
"field": "author_and_contributor"
1
This is a good solution! Although I have to say thatauthor_and_contributorcan be of typekeywordthus removing this problem withfielddata. (Tested with ES6.)
– Nikolay Vasiliev
Mar 23 at 11:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298085%2fmerge-the-results-of-two-aggregations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Well if you can update your mappings and add a field this should work. Please not it could be really slow (agg on string are slow and shouldnot be over used). Note if author = contributor in the same doc the agg will wont count 2 occurance (good news).
"mappings":
"test":
"properties":
"contributor":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author_and_contributor":
"type": "string",
"fielddata": true
"size": 0,
"aggs":
"author_contrib_agg":
"terms":
"field": "author_and_contributor"
1
This is a good solution! Although I have to say thatauthor_and_contributorcan be of typekeywordthus removing this problem withfielddata. (Tested with ES6.)
– Nikolay Vasiliev
Mar 23 at 11:19
add a comment |
Well if you can update your mappings and add a field this should work. Please not it could be really slow (agg on string are slow and shouldnot be over used). Note if author = contributor in the same doc the agg will wont count 2 occurance (good news).
"mappings":
"test":
"properties":
"contributor":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author_and_contributor":
"type": "string",
"fielddata": true
"size": 0,
"aggs":
"author_contrib_agg":
"terms":
"field": "author_and_contributor"
1
This is a good solution! Although I have to say thatauthor_and_contributorcan be of typekeywordthus removing this problem withfielddata. (Tested with ES6.)
– Nikolay Vasiliev
Mar 23 at 11:19
add a comment |
Well if you can update your mappings and add a field this should work. Please not it could be really slow (agg on string are slow and shouldnot be over used). Note if author = contributor in the same doc the agg will wont count 2 occurance (good news).
"mappings":
"test":
"properties":
"contributor":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author_and_contributor":
"type": "string",
"fielddata": true
"size": 0,
"aggs":
"author_contrib_agg":
"terms":
"field": "author_and_contributor"
Well if you can update your mappings and add a field this should work. Please not it could be really slow (agg on string are slow and shouldnot be over used). Note if author = contributor in the same doc the agg will wont count 2 occurance (good news).
"mappings":
"test":
"properties":
"contributor":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author":
"type": "keyword",
"copy_to": "author_and_contributor"
,
"author_and_contributor":
"type": "string",
"fielddata": true
"size": 0,
"aggs":
"author_contrib_agg":
"terms":
"field": "author_and_contributor"
answered Mar 22 at 13:53
LeBigCatLeBigCat
666312
666312
1
This is a good solution! Although I have to say thatauthor_and_contributorcan be of typekeywordthus removing this problem withfielddata. (Tested with ES6.)
– Nikolay Vasiliev
Mar 23 at 11:19
add a comment |
1
This is a good solution! Although I have to say thatauthor_and_contributorcan be of typekeywordthus removing this problem withfielddata. (Tested with ES6.)
– Nikolay Vasiliev
Mar 23 at 11:19
1
1
This is a good solution! Although I have to say that
author_and_contributor can be of type keyword thus removing this problem with fielddata. (Tested with ES6.)– Nikolay Vasiliev
Mar 23 at 11:19
This is a good solution! Although I have to say that
author_and_contributor can be of type keyword thus removing this problem with fielddata. (Tested with ES6.)– Nikolay Vasiliev
Mar 23 at 11:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298085%2fmerge-the-results-of-two-aggregations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown