Answer the question
In order to leave comments, you need to log in
How to do aggregation?
Good afternoon.
There is an index in elasticsearch, documents have a parameters field that stores an array of elements, elements are ordinary strings.
I'm trying to make a request to find documents in which the parameters array contains, for example, 'elem1' and 'elem2' ([...... ..'elem1', ........'elem2'])
After I have selected them, make them distinct (find out the number of array values in this selection), I do it using aggregation:
aggs: {
results: {
filter: {
terms: {
parameters: ['elem1', 'elem2']
}
},
terms: {
field: 'parameters',
size: 200
}
}
}
filter: {
terms: {
parameters: ['elem1', 'elem2']
}
}
Answer the question
In order to leave comments, you need to log in
Yes, I made the request a little wrong) Here's how to do a search with the content of the value in the array, followed by aggregation:
aggs: {
results: {
filter: {
bool: {
must: [
{
term: {
parameters: 'elem1'
}
},
{
term: {
parameters: 'elem2'
}
}
]
}
},
aggs: {
count:{
terms: {
field: 'parameters',
size: 200
}
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question