Elasticsearch does not compute repeated values in the metric aggregation

Hi guys.

I've been trials for metric aggregation. I noticed something
interesting. Elasticsearch does not compute repeated values in the metric
aggregation.

For example, as my documents

{name:"kimchy",
exam_notes:["6","5","6","3"]
}

When I run the metric aggregation, the result is as follows.

GET mytest/test/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"sum_exam_notes": {
"sum": {
"field": "exam_notes"
}
}
}
}

"aggregations": {
"sum_exam_notes": {
"value": 14
}
}

6 + 5 + 6 + 3 instead of 6 + 5 + 3

Why?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/43261e05-aaee-48e8-9e2a-d1ce8abf7904%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Indeed. For now, the way your field is indexed looks like this:

Value, Doc ID
6, 1
5, 1
3, 1

(I simplify a lot)

So, when we do the sum, we only sum different values (I mean within the same document).

The only workaround I can see here is to detect a index time that you have some identical values and instead of indexing
["6","5","6","3"]

Index in another field deduplicated values:

["12","5","3"]

Doc1: {name:"kimchy",
exam_note:6
}
Doc2: {name:"kimchy",
exam_note:5
}
Doc3: {name:"kimchy",
exam_note:6
}
Doc4: {name:"kimchy",
exam_note:3
}

It will give you the expected result.

Still, I think this should be added in documentation. Wanna contribute?

--
David Pilato | Technical Advocate | elasticsearch.com
david.pilato@elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 22 septembre 2014 à 18:58:23, Terra Sacer (terrasacer@gmail.com) a écrit:

Hi guys.

I've been trials for metric aggregation. I noticed something interesting. Elasticsearch does not compute repeated values in the metric aggregation.

For example, as my documents

{name:"kimchy",
exam_notes:["6","5","6","3"]
}

When I run the metric aggregation, the result is as follows.

GET mytest/test/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"sum_exam_notes": {
"sum": {
"field": "exam_notes"
}
}
}
}

"aggregations": {
"sum_exam_notes": {
"value": 14
}
}

6 + 5 + 6 + 3 instead of 6 + 5 + 3

Why?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/43261e05-aaee-48e8-9e2a-d1ce8abf7904%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/etPan.54206256.62bbd95a.825%40MacBook-Air-de-David.local.
For more options, visit https://groups.google.com/d/optout.

Hi David,

Thank you for your answer.

Still, I think this should be added in documentation.

Absolutely agree.

I would like to contribute, but how?

On Monday, September 22, 2014 8:54:47 PM UTC+3, David Pilato wrote:

Indeed. For now, the way your field is indexed looks like this:

Value, Doc ID
6, 1
5, 1
3, 1

(I simplify a lot)

So, when we do the sum, we only sum different values (I mean within the
same document).

The only workaround I can see here is to detect a index time that you have
some identical values and instead of indexing

["6","5","6","3"]

Index in another field deduplicated values:

["12","5","3"]

Doc1: {name:"kimchy",
exam_note:6
}

Doc2: {name:"kimchy",
exam_note:5
}

Doc3: {name:"kimchy",
exam_note:6
}

Doc4: {name:"kimchy",
exam_note:3
}

It will give you the expected result.

Still, I think this should be added in documentation. Wanna contribute?

--
David Pilato | Technical Advocate | elasticsearch.com
http://elasticsearch.com

david....@elasticsearch.com <javascript:>
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr | @scrutmydocs
http://twitter.com/scrutmydocs
https://twitter.com/scrutmydocs

Le 22 septembre 2014 à 18:58:23, Terra Sacer (terra...@gmail.com
<javascript:>) a écrit:

Hi guys.

I've been trials for metric aggregation. I noticed something
interesting. Elasticsearch does not compute repeated values in the metric
aggregation.

For example, as my documents

{name:"kimchy",
exam_notes:["6","5","6","3"]
}

When I run the metric aggregation, the result is as follows.

GET mytest/test/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"sum_exam_notes": {
"sum": {
"field": "exam_notes"
}
}
}
}

"aggregations": {
"sum_exam_notes": {
"value": 14
}
}

6 + 5 + 6 + 3 instead of 6 + 5 + 3

Why?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/43261e05-aaee-48e8-9e2a-d1ce8abf7904%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/43261e05-aaee-48e8-9e2a-d1ce8abf7904%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ae73f864-480b-4847-87f1-85ed4641d854%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cool. That’s easy. Read this: https://github.com/elasticsearch/elasticsearch/blob/master/CONTRIBUTING.md

If you click on Edit button at http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html it will fork and edit the source page.

:slight_smile:

Best

--
David Pilato | Technical Advocate | elasticsearch.com
david.pilato@elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 22 septembre 2014 à 21:05:15, Terra Sacer (terrasacer@gmail.com) a écrit:

Hi David,

Thank you for your answer.

Still, I think this should be added in documentation.

Absolutely agree.

I would like to contribute, but how?

On Monday, September 22, 2014 8:54:47 PM UTC+3, David Pilato wrote:
Indeed. For now, the way your field is indexed looks like this:

Value, Doc ID
6, 1
5, 1
3, 1

(I simplify a lot)

So, when we do the sum, we only sum different values (I mean within the same document).

The only workaround I can see here is to detect a index time that you have some identical values and instead of indexing
["6","5","6","3"]

Index in another field deduplicated values:

["12","5","3"]

Doc1: {name:"kimchy",
exam_note:6
}
Doc2: {name:"kimchy",
exam_note:5
}
Doc3: {name:"kimchy",
exam_note:6
}
Doc4: {name:"kimchy",
exam_note:3
}

It will give you the expected result.

Still, I think this should be added in documentation. Wanna contribute?

--
David Pilato | Technical Advocate | elasticsearch.com
david....@elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 22 septembre 2014 à 18:58:23, Terra Sacer (terra...@gmail.com) a écrit:

Hi guys.

I've been trials for metric aggregation. I noticed something interesting. Elasticsearch does not compute repeated values in the metric aggregation.

For example, as my documents

{name:"kimchy",
exam_notes:["6","5","6","3"]
}

When I run the metric aggregation, the result is as follows.

GET mytest/test/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"sum_exam_notes": {
"sum": {
"field": "exam_notes"
}
}
}
}

"aggregations": {
"sum_exam_notes": {
"value": 14
}
}

6 + 5 + 6 + 3 instead of 6 + 5 + 3

Why?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/43261e05-aaee-48e8-9e2a-d1ce8abf7904%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ae73f864-480b-4847-87f1-85ed4641d854%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/etPan.54207658.333ab105.825%40MacBook-Air-de-David.local.
For more options, visit https://groups.google.com/d/optout.

Hi David.

Thank you for your guidance and support.

Best regards.

On Monday, September 22, 2014 10:20:32 PM UTC+3, David Pilato wrote:

Cool. That’s easy. Read this:
https://github.com/elasticsearch/elasticsearch/blob/master/CONTRIBUTING.md

https://github.com/elasticsearch/elasticsearch/blob/master/CONTRIBUTING.md
I
https://github.com/elasticsearch/elasticsearch/blob/master/CONTRIBUTING.mdf
you click on Edit button at
Elasticsearch Platform — Find real-time answers at scale | Elastic it
will fork and edit the source page.

:
https://github.com/elasticsearch/elasticsearch/blob/master/CONTRIBUTING.md
)

Best

--
David Pilato | Technical Advocate | elasticsearch.com
http://elasticsearch.com

david....@elasticsearch.com <javascript:>
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr | @scrutmydocs
http://twitter.com/scrutmydocs
https://twitter.com/scrutmydocs

Le 22 septembre 2014 à 21:05:15, Terra Sacer (terra...@gmail.com
<javascript:>) a écrit:

Hi David,

Thank you for your answer.

Still, I think this should be added in documentation.

Absolutely agree.

I would like to contribute, but how?

On Monday, September 22, 2014 8:54:47 PM UTC+3, David Pilato wrote:

Indeed. For now, the way your field is indexed looks like this:

Value, Doc ID
6, 1
5, 1
3, 1

(I simplify a lot)

So, when we do the sum, we only sum different values (I mean within the
same document).

The only workaround I can see here is to detect a index time that you
have some identical values and instead of indexing

["6","5","6","3"]

Index in another field deduplicated values:

["12","5","3"]


Doc1: {name:"kimchy",

exam_note:6
}

  Doc2: {name:"kimchy",

exam_note:5
}

     Doc3: {name:"kimchy",

exam_note:6
}

    Doc4: {name:"kimchy",

exam_note:3
}

It will give you the expected result.

Still, I think this should be added in documentation. Wanna contribute?

--

Le 22 septembre 2014 à 18:58:23, Terra Sacer (terra...@gmail.com) a
écrit:

Hi guys.

I've been trials for metric aggregation. I noticed something
interesting. Elasticsearch does not compute repeated values in the metric
aggregation.

For example, as my documents

{name:"kimchy",
exam_notes:["6","5","6","3"]
}

When I run the metric aggregation, the result is as follows.

GET mytest/test/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"sum_exam_notes": {
"sum": {
"field": "exam_notes"
}
}
}
}

"aggregations": {
"sum_exam_notes": {
"value": 14
}
}

6 + 5 + 6 + 3 instead of 6 + 5 + 3

Why?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/43261e05-aaee-48e8-9e2a-d1ce8abf7904%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/43261e05-aaee-48e8-9e2a-d1ce8abf7904%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ae73f864-480b-4847-87f1-85ed4641d854%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/ae73f864-480b-4847-87f1-85ed4641d854%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/2d405c3c-a875-4673-8d55-7e97b448d3d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.