Get count unique values from field


(Владислав Властовский) #1

Hi,

I need to get just two numbers: the number of documents in the index, and
the number of unique values in the field "relation". I wanted to use the
facet, but I transfer the sets of terms (over 100,000) to calculate a
single number.

Examples of documents:
{
"relation": 1
},
{
"relation": 2
},
{
"relation": 1
}

In SQL, the number data can be obtained in one query SELECT COUNT(*),
COUNT(DISTINCT relation) FROM table;

How best can I get this information using the ES?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(David Pilato) #2

I thin Terms facet is the way to go here. See http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet/

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 11 sept. 2013 à 11:06, Владислав Властовский me@vlastv.ru a écrit :

Hi,

I need to get just two numbers: the number of documents in the index, and the number of unique values in the field "relation". I wanted to use the facet, but I transfer the sets of terms (over 100,000) to calculate a single number.

Examples of documents:
{
"relation": 1
},
{
"relation": 2
},
{
"relation": 1
}

In SQL, the number data can be obtained in one query SELECT COUNT(*), COUNT(DISTINCT relation) FROM table;

How best can I get this information using the ES?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Владислав Властовский) #3

As I said above, do not want to receive as a result of the facet 100
thousand terms, and need to get a single number - the number of unique.

среда, 11 сентября 2013 г., 13:31:45 UTC+4 пользователь David Pilato
написал:

I thin Terms facet is the way to go here. See
http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet/

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
| @scrutmydocs https://twitter.com/scrutmydocs

Le 11 sept. 2013 à 11:06, Владислав Властовский <m...@vlastv.ru<javascript:>>
a écrit :

Hi,

I need to get just two numbers: the number of documents in the index, and
the number of unique values in the field "relation". I wanted to use the
facet, but I transfer the sets of terms (over 100,000) to calculate a
single number.

Examples of documents:
{
"relation": 1
},
{
"relation": 2
},
{
"relation": 1
}

In SQL, the number data can be obtained in one query SELECT COUNT(*),
COUNT(DISTINCT relation) FROM table;

How best can I get this information using the ES?

--
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:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Jun Ohtani) #4

Hi,

"relation" field is a number field?
If "relation" field is a Number field,I think that you can use statistical
facet.
http://www.elasticsearch.org/guide/reference/api/search/facets/statistical-facet/

Notice "memory considerations" section is important.

example following.

query:
{
"query": {
"match_all": {}
},
"facets": {
"stats1": {
"statistical": {
"field": "relation"
}
}
}
}

response:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{...
}
]
},
"facets": {
"stats1": {
"_type": "statistical",
"count": 3,
"total": 4,
"min": 1,
"max": 2,
"mean": 1.3333333333333333,
"sum_of_squares": 6,
"variance": 0.22222222222222232,
"std_deviation": 0.4714045207910318
}
}
}

2013/9/11 Владислав Властовский me@vlastv.ru

As I said above, do not want to receive as a result of the facet 100
thousand terms, and need to get a single number - the number of unique.

среда, 11 сентября 2013 г., 13:31:45 UTC+4 пользователь David Pilato
написал:

I thin Terms facet is the way to go here. See http://www.elasticsearch.**
org/guide/reference/api/**search/facets/terms-facet/http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet/

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
|** @scrutmydocs https://twitter.com/scrutmydocs

Le 11 sept. 2013 à 11:06, Владислав Властовский m...@vlastv.ru a écrit
:

Hi,

I need to get just two numbers: the number of documents in the index, and
the number of unique values in the field "relation". I wanted to use the
facet, but I transfer the sets of terms (over 100,000) to calculate a
single number.

Examples of documents:
{
"relation": 1
},
{
"relation": 2
},
{
"relation": 1
}

In SQL, the number data can be obtained in one query SELECT COUNT(*),
COUNT(DISTINCT relation) FROM table;

How best can I get this information using the ES?

--
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.

For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--

Jun Ohtani
blog : http://blog.johtani.info

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Jun Ohtani) #5

Sorry...
I misunderstood problem...

2013/09/11 19:12 "Jun Ohtani" johtani@gmail.com:

Hi,

"relation" field is a number field?
If "relation" field is a Number field,I think that you can use
statistical facet.

http://www.elasticsearch.org/guide/reference/api/search/facets/statistical-facet/

Notice "memory considerations" section is important.

example following.

query:
{
"query": {
"match_all": {}
},
"facets": {
"stats1": {
"statistical": {
"field": "relation"
}
}
}
}

response:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{...
}
]
},
"facets": {
"stats1": {
"_type": "statistical",
"count": 3,
"total": 4,
"min": 1,
"max": 2,
"mean": 1.3333333333333333,
"sum_of_squares": 6,
"variance": 0.22222222222222232,
"std_deviation": 0.4714045207910318
}
}
}

2013/9/11 Владислав Властовский me@vlastv.ru

As I said above, do not want to receive as a result of the facet 100
thousand terms, and need to get a single number - the number of unique.

среда, 11 сентября 2013 г., 13:31:45 UTC+4 пользователь David Pilato
написал:

I thin Terms facet is the way to go here. See
http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet/

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

Le 11 sept. 2013 à 11:06, Владислав Властовский m...@vlastv.ru a
écrit :

Hi,

I need to get just two numbers: the number of documents in the index,
and the number of unique values in the field "relation". I wanted to use
the facet, but I transfer the sets of terms (over 100,000) to calculate a
single number.

Examples of documents:
{
"relation": 1
},
{
"relation": 2
},
{
"relation": 1
}

In SQL, the number data can be obtained in one query SELECT COUNT(*),
COUNT(DISTINCT relation) FROM table;

How best can I get this information using the ES?

--
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.

For more options, visit https://groups.google.com/groups/opt_out.

--
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.

For more options, visit https://groups.google.com/groups/opt_out.

--

Jun Ohtani
blog : http://blog.johtani.info

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Jun Ohtani) #6

Hi

Related these issues.These issues is still open .


2013/09/11 18:37 "Владислав Властовский" me@vlastv.ru:

As I said above, do not want to receive as a result of the facet 100
thousand terms, and need to get a single number - the number of unique.

среда, 11 сентября 2013 г., 13:31:45 UTC+4 пользователь David Pilato
написал:

I thin Terms facet is the way to go here. See http://www.elasticsearch.**
org/guide/reference/api/**search/facets/terms-facet/http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet/

David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
|** @scrutmydocs https://twitter.com/scrutmydocs

Le 11 sept. 2013 à 11:06, Владислав Властовский m...@vlastv.ru a écrit
:

Hi,

I need to get just two numbers: the number of documents in the index, and
the number of unique values in the field "relation". I wanted to use the
facet, but I transfer the sets of terms (over 100,000) to calculate a
single number.

Examples of documents:
{
"relation": 1
},
{
"relation": 2
},
{
"relation": 1
}

In SQL, the number data can be obtained in one query SELECT COUNT(*),
COUNT(DISTINCT relation) FROM table;

How best can I get this information using the ES?

--
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.
For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #7