How would I get the values of all the languages
from the records and make them unique.
Records
PUT items/1
{ "language" : 10 }
PUT items/2
{ "language" : 11 }
PUT items/3
{ "language" : 10 }
Query
GET items/_search
{ ... }
# => Expected Response
[10, 11]
Any help would be great.
Elasticsearch is a powerful search engine that can be used to get distinct values. To get started, you need to create an index and specify the mapping for the fields you want to search. Then, you can use the search API to query the index and get the distinct values for the fields you want.
Re: kql query for distinct values If that is not an issue then after you get your host and your displayName, you can concatenate (using the strcat command) and then perform another distinct on the concatenated string. Hope this is what you are looking for.
A single-value metrics aggregation that calculates an approximate count of distinct values. Values can be extracted either from specific fields in the document or generated by a script.
You can use a Metric visualization and just use the "count" metric for this. There are many ways to do this, generally in most visualizations, you can: use "Unique Count" on the personId field as the metric. use a terms aggregation on the organizationId field for the X-Axis (or split rows in a table visualization).
You can use the terms aggregation.
{
"size": 0,
"aggs" : {
"langs" : {
"terms" : { "field" : "language", "size" : 500 }
}
}}
The size
parameter within the aggregation specifies the maximum number of terms to include in the aggregation result. If you need all results, set this to a value that is larger than the number of unique terms in your data.
A search will return something like:
{
"took" : 16,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"hits" : {
"total" : 1000000,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"langs" : {
"buckets" : [ {
"key" : "10",
"doc_count" : 244812
}, {
"key" : "11",
"doc_count" : 136794
}, {
"key" : "12",
"doc_count" : 32312
} ]
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With