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;








0















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.










share|improve this question




























    0















    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.










    share|improve this question
























      0












      0








      0








      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.










      share|improve this question














      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.







      elasticsearch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 10:54









      tomorrow__tomorrow__

      2502512




      2502512






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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"









          share|improve this answer


















          • 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











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



          );













          draft saved

          draft discarded


















          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









          1














          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"









          share|improve this answer


















          • 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















          1














          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"









          share|improve this answer


















          • 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













          1












          1








          1







          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"









          share|improve this answer













          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"










          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 13:53









          LeBigCatLeBigCat

          666312




          666312







          • 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












          • 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







          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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해