Questions tagged [elasticsearch-aggregation]
1111 questions
5
votes
1 answer
ElasticSearch pick one product from each category with top score
I am trying to query ES index which contains product information, having product_id, category_id and variant_id fields. Each product belong to certain category and variant:
{
"product_id" : "PRODUCT_12345",
"category_id" : 1,
…

dilkash
- 562
- 3
- 15
5
votes
1 answer
Using date_histogram with fixed_interval (30d) unexpected bucket start
I have a requirement to get data aggregated per 30 days (not month) so I'm using a date_histogram with "fixed_interval": "30d" to get that data. For example, if the user wants the last 90 days aggregations, there should be 3 buckets: [90-60, 60-30,…

Claudio
- 53
- 6
5
votes
1 answer
How to correctly query inside of terms aggregate values in elasticsearch, using include and regex?
How do you filter out/search in aggregate results efficiently?
Imagine you have 1 million documents in elastic search. In those documents, you have a multi_field (keyword, text) tags:
{
...
tags: ['Race', 'Racing', 'Mountain Bike',…

mclenithan
- 275
- 1
- 14
5
votes
2 answers
Composite Aggregation in ElasticSearch Java
I went through many articles to find any appropriate solution to add a Composite aggregation but did not find any relevant solution.
I have achieved it . See the answer, hope this will help.

Chirag Gupta
- 115
- 1
- 7
5
votes
2 answers
How to include all docs in ElasticSearch Aggregation and avoid sum_other_doc_count > 0
ES is not mainstream for my work, and there's one behavior I'm not able to correct. I have a fairly simple aggregation query:
GET /my_index/_search
{
"size": 0,
"query": {
"bool": {
"must": [
{
"match": {
…

Reuven Trabin
- 451
- 7
- 18
5
votes
3 answers
"Filter then Aggregation" or just "Filter Aggregation"?
I am working on ES recently and I found that I could achieve the almost same result but I have no clear idea as to the DIFFERENCE between these two.
"Filter then Aggregation"
POST kibana_sample_data_flights/_search
{
"size": 0,
"query": {
…

Hearen
- 7,420
- 4
- 53
- 63
5
votes
1 answer
Return only match fields instead of returning the whole document
Return only matched source instead of returning the whole document of elastic search that contain that text
Suppose I have a data in this format,
POST /bookdb_index/book/_bulk
{ "index": { "_id": 1 }}
{ "title": "Elasticsearch: The Definitive…

mansi
- 73
- 5
5
votes
1 answer
ElasticSearch: Aggregate Over a Collected Set of Results
Let's say I have a set of... burgers...
For each burger, I have a set of images relating to each component of the burger.
Unfortunately, there isn't any consistency in the structure of these components (I didn't write it).
Here is an example of two…

WebWanderer
- 10,380
- 3
- 32
- 51
5
votes
0 answers
how to get rank of a document in elastic search with single query?
We have elastic search index with documents having the id and price of the stocks.
We want to build a system where the user gives stock id as the input and it gets back the rank of that document. I have two queries that can solve this:
Get the…

Sahil Sharma
- 3,847
- 6
- 48
- 98
5
votes
1 answer
Range ElasticSearch Aggregation
I need to compute a pipeline aggregation in ElasticSearch and I can't figure out how to express it.
Each document has an email address and an amount. I need to output range buckets of amount counts, grouped by unique email.
{ "0 - 99": 300, "100 -…

Ben
- 15,010
- 11
- 58
- 90
5
votes
2 answers
Elasticsearch aggregation turns results to lowercase
I've been playing with ElasticSearch a little and found an issue when doing aggregations.
I have two endpoints, /A and /B. In the first one I have parents for the second one. So, one or many objects in B must belong to one object in A. Therefore,…

RecuencoJones
- 2,747
- 3
- 22
- 21
4
votes
1 answer
Elasticsearch: Tricky aggregation with sum and comparison
I am trying to pull statistics from my elastic cluster I cannot figure out.
In the end what I want to achieve is a count of streams (field: status) over time (field: timestamp) for a specific item (field: media).
The data are logs from nginx with…

OpenHaus
- 97
- 2
- 9
- 17
4
votes
1 answer
Convert timestamps to datetime for use in Elasticsearch aggregations
I have an index of SendGrid event data:
"_source": {
"externalId": "9283cc1d-b003-xxxx-a5af-84fcf31c4181",
"email": "test@test.com",
"timestamp": 1616515214,
"event": "processed",
"uid": null,
"id": null,
…

Alex
- 1,857
- 3
- 36
- 51
4
votes
1 answer
Text fields are not optimised for operations that require per-document : Elasticsearch
This is my Entity:
public class RecentTransactionBo {
@JsonProperty("timestamp")
@Field(type = FieldType.Date, format = DateFormat.basic_date_time)
@Id
@Temporal(TemporalType.DATE)
private Date creationDate;
private…

Mayank Jha
- 939
- 3
- 12
- 24
4
votes
0 answers
Bucket_script aggregation on filters aggregation not showing results
I have "event" (like clicks on websites) documents in a index. Now I want to to calculate the ratio between events with name=x and events with name=y. I first use a "filters" agg to split up my documents into two buckets and then I use a…

Anton
- 936
- 1
- 8
- 27