Nested aggregation empty bucket


(Martin Zajíc) #1

Hi,
I have problem with aggregation, which return no bucket.
(it's more complicated I did drop useless stuff for this example, thats why it's competence inside competence without any other field)

my mapping:

{
    "mappings": {
      "competence": {
        "properties": {
          "competence": {
            "type": "nested",
            "properties": {
              "type": {
                "type": "nested",
                "properties": {
                  "name": {
                    "type": "keyword"
                  },
                  "value": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        
        }
      }
    }
}

typical record looks like this:

{
  "_source": {
    "competence": {
      "type": {
        "value": 4,
        "name": "TYPE_4"
      }
    }
  }
}

but when I run query:

{
  "size": 0,
  "aggs": {
    "nested_type": {
      "nested": {
        "path": "competence"
      },
      "aggs": {
        "cmp_type": {
          "terms": {
            "field": "type.value"
          }
        }
      }
    }
  },
  "query": {
    "match_all": {}
  }
}

but it will return no bucket

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 26254,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "nested_type": {
      "doc_count": 26254,
      "cmp_type": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": []
      }
    }
  }
}

(swarmee.net) #2

You need the full field path in the final terms aggregation. I.e. competence.type.value


(Martin Zajíc) #3

I'll get same result with fullpath

{
  "size": 0,
  "aggs": {
    "nested_type": {
      "nested": {
        "path": "competence"
      },
      "aggs": {
        "cmp_type": {
          "terms": {
            "field": "competence.type.value"
          }
        }
      }
    }
  },
  "query": {
    "match_all": {}
  }
}

-->

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 26254,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "nested_type": {
      "doc_count": 26254,
      "cmp_type": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": []
      }
    }
  }
}

(swarmee.net) #4

Sorry - you also need to go down to the required nested path in the initial aggregation. So... competence.type


(Martin Zajíc) #5

That works than you


(system) #6

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.