PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 25, 2022

[FIXED] How can I return more than 10 buckets from an aggs, multi-terrms query using elasticsearch?

 October 25, 2022     elasticsearch, elasticsearch-aggregation     No comments   

Issue

I'm using Elasticsearch 8.4.1 and I'm trying to return more than 10 buckets from this working query:

GET vaersdata_2/_search
{
  "aggs": {
    "age_died after_shot": {
        "multi_terms": {
        "terms": [{ 
          "field": "AGE_YRS"
        }, {
          "field": "DIED"
        }]
      }
    }
  }
}

So I added size into the mix, but after numerous failed attempts, it throws an error. This query didn't show errors in the console until I ran it:

GET vaersdata_2/_search
{
  "aggs": {
      "size": 0,
    "age_died after_shot": {
        "multi_terms": {
        "terms": [{ 
          "field": "AGE_YRS",
          "size" : 100
        }, {
          "field": "DIED"
        }]
      }
    }
  }
}

and then I get this error:

"type": "parsing_exception", "reason": "Aggregation definition for [size starts with a [VALUE_NUMBER], expected a [START_OBJECT].", "line": 3, "col": 15 }, "status": 400

I've seen size used as a solution for this using nested term queries, but how do I do this for an aggs, multi-terrms query?


Solution

Tldr;

Quite close, but the size arguments is not place in the right spot.

Solution

GET vaersdata_2/_search
{
  "aggs": {
    "age_died after_shot": {
        "multi_terms": {
        "terms": [{ 
          "field": "AGE_YRS"
        }, {
          "field": "DIED"
        }],
        "size" : 100
      }
    }
  }
}

The following query has been tested with kibana 8.4.1

GET kibana_sample_data_ecommerce/_search
{
  "aggs": {
    "multi_bucket": {
      "multi_terms": {
        "size": 12,
        "terms": [{
          "field": "customer_first_name.keyword" 
        }, {
          "field": "customer_last_name.keyword"
        }]
      }
    }
  }
}


Answered By - Paulo
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing