# Kibana CHART is approximating NESTED objects price. Why?

**URL:** <https://discuss.elastic.co/t/kibana-chart-is-approximating-nested-objects-price-why/131083>\
**Category:** Kibana\
**Created:** [May 9, 2018, 1:54am UTC](https://discuss.elastic.co/t/kibana-chart-is-approximating-nested-objects-price-why/131083 "2018-05-09T01:54:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vannazux](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vannazux/32/30957_2.png) [@Vannazux](https://discuss.elastic.co/u/Vannazux)\
**Post date:** [May 9, 2018, 1:54am UTC](https://discuss.elastic.co/t/kibana-chart-is-approximating-nested-objects-price-why/131083/1 "2018-05-09T01:54:00Z")

</div>

I built a bar chart graph that aggregates orders per label bucket (e.g: USD/CAD). Then I display the sum of orders price per bucket for each of the orders inside it.

My chart visualization returns a wrong price which seems to be coming approximated

This is my graph query request debug

```
{
  "size": 0,
  "_source": {
    "excludes": []
  },
  "aggs": {
    "3": {
      "terms": {
        "field": "label.keyword",
        "size": 2,
        "order": {
          "_term": "desc"
        }
      },
      "aggs": {
        "2": {
          "terms": {
            "field": "orders.id",
            "size": 40,
            "order": {
              "1": "desc"
            }
          },
          "aggs": {
            "1": {
              "sum": {
                "field": "orders.price"
              }
            }
          }
        }
      }
    }
  },
  "stored_fields": [
    "*"
  ],
  "script_fields": {},
  "docvalue_fields": [],
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "filter": [],
      "should": [],
      "must_not": []
    }
  }
}

```

And this is the response, which confirms the the `orders.price` value is being approximated

```
{
  "took": 9,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 124,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "3": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 122,
      "buckets": [
        {
          "2": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
              {
                "1": {
                  "value": 0.003690590019687079
                },
                "key": 213481,
                "doc_count": 1
              },
              {
                "1": {
                  "value": 0.003690590019687079
                },
                "key": 213482,
                "doc_count": 1
              },
              {
                "1": {
                  "value": 0.003690590019687079
                },
                "key": 213483,
                "doc_count": 1
              },
              {
                "1": {
                  "value": 0.003690590019687079
                },
                "key": 213484,
                "doc_count": 1
              },
              ...

```

And this is the photo that confirms that my data is there and should be retrieving the right price from the `order.price`

What is more strange is that when I flatten my data and stop using an array of nested orders, the same graph will work and display the correct value for each order.

However, I need to have this bar chart working with my source data above. My data is structured with nested orders array for each label. Am I doing anything wrong while building my graph?

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [May 9, 2018, 5:32pm UTC](https://discuss.elastic.co/t/kibana-chart-is-approximating-nested-objects-price-why/131083/2 "2018-05-09T17:32:11Z")

</div>

@thomasneirynck thanks 🙂

---

<div class="post-metadata">

**Author:** ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)\
**Post date:** [May 9, 2018, 6:26pm UTC](https://discuss.elastic.co/t/kibana-chart-is-approximating-nested-objects-price-why/131083/3 "2018-05-09T18:26:38Z")

</div>

hi @Vannazux ,

it's hard to tell from here how much the values deviate. What are the exact values you are expecting?

I don't think we can do much on the Kibana-end for this. I do believe that Elasticsearch will approximate any kind of aggregation-values when using Terms-aggregation, and that the sorting plays into that.

Could you share some sample commands that we can copy-paste in the dev-console that illustrates the problem, so we can reproduce here?

---

<div class="post-metadata">

**Author:** ![Vannazux](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vannazux/32/30957_2.png) [@Vannazux](https://discuss.elastic.co/u/Vannazux)\
**Post date:** [May 9, 2018, 6:50pm UTC](https://discuss.elastic.co/t/kibana-chart-is-approximating-nested-objects-price-why/131083/4 "2018-05-09T18:50:09Z")

</div>

Hi @thomasneirynck,

Thanks for the answer.

I am expecting the values in the blue arrows from the discovery tab picture of the `orderbookindex` above.

The picture shows each order has its own price. However, my query response shows that Kibana is returning the same value for every order in a wrong way. I realized that Kibana is not approximating but worst it is returning the same wrong value for every order price, look:

```
{
                "1": {
                  "value": 0.003690590019687079
                },
                "key": 213482,
                "doc_count": 1
              },
              {
                "1": {
                  "value": 0.003690590019687079
                },
                "key": 213483,
                "doc_count": 1
              },

```

I believe this has to do with some problem leading with nested types on Kibana but I am not sure.

Regarding the codes, I am new to ELK. I might not know exactly what to share, let me know what I could share that could help. Basically, I am receiving this data in `orderbookindex` and executing a query in visualization tab using a bar chart. The query is done by the editor displayed in the section "query debug" and the response comes as states in the query "response section" code above. I don't know how to reproduce the `orderbookindex` I have here but maybe if I share my index from a GET request it might help reproducing it from there.

```
    {
  "orderbookindex": {
    "aliases": {},
    "mappings": {
      "orderbook": {
        "properties": {
          "exchange": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "id": {
            "type": "integer"
          },
          "label": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "length": {
            "type": "integer"
          },
          "orders": {
            "type": "nested",
            "properties": {
              "exchange": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "id": {
                "type": "integer"
              },
              "label": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "orderbookId": {
                "type": "integer"
              },
              "ordertype": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "pair1": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "pair2": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "price": {
                "type": "double"
              },
              "quantity": {
                "type": "double"
              },
              "timestamp": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "total": {
                "type": "double"
              }
            }
          },
          "timestamp": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1525917072851",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "Uxj9HWRISxSKY2kRnUP4rA",
        "version": {
          "created": "6020499"
        },
        "provided_name": "orderbookindex"
      }
    }
  }
}

```

What call more my attention is that when I build another index with the same information of `orders` without using the nested `"_type": "orderbook"` as state in discovery tab picture, the exact Kibana query will work and retrieves the right price for each order (the prices in the blue arrows)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 6, 2018, 6:50pm UTC](https://discuss.elastic.co/t/kibana-chart-is-approximating-nested-objects-price-why/131083/5 "2018-06-06T18:50:10Z")

</div>

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