I have the following data in my elasticsearch tenders
index:
{
"_index": "tenders",
"_id": "204cda9e9f1541758a6e7be03c296185",
"_score": 1,
"_source": {
"tenderId": "204cda9e9f1541758a6e7be03c296185",
"status": "complete",
"title": "Цвяхи - 80, Цвяхи - 100",
"publicTenderId": "UA-2023-12-15-017779-a",
"items": [
{
"id": "e063998b195545ce851b6827ed358905",
"classification": {
"scheme": "ДК021",
"cpv": "44530000-4"
}
},
{
"id": "8b6325cf93d94bb59bbf575950ffc372",
"classification": {
"scheme": "ДК021",
"cpv": "44530000-4"
}
}
],
"value": {
"amount": 210,
"currency": "UAH"
},
"suppliers": [
{
"contractId": "5a65a7e538e64c6297cf20e0995f0a2a",
"contractAwardId": "151a9da56d334984b4b686ca7be175bf",
"name": "ФОП Кузьменко Костянтин Андрійович",
"identifier": {
"scheme": "UA-EDR",
"id": "2096015130"
}
}
],
"procuringEntity": {
"name": "ВІДДІЛ З ГУМАНІТАРНИХ ПИТАНЬ ОВРУЦЬКОЇ МІСЬКОЇ РАДИ",
"organization_id": "41818470",
"organization_scheme": "UA-EDR",
"address": {
"streetAddress": "ВУЛИЦЯ ТАРАСА ШЕВЧЕНКА, БУДИНОК 31А",
"locality": "Овруч",
"region": "Житомирська область",
"postalCode": "11101",
"countryName": "Україна"
}
},
"date": "2023-12-15T16:03:31.067236+02:00",
"dateCreated": "2023-12-15T16:01:22.096013+02:00",
"dateModified": "2023-12-15T16:03:31.067236+02:00",
"contracts": [
{
"dateSigned": "2023-12-15T09:00:00+02:00"
}
],
"indexedAt": "2024-07-03T03:42:40.355Z"
}
}
Now I need to find top-3 procuringEntity
with the following conditions:
- at least one item in
_source.items.classification.cpv
matches the one provided by user - procuring entities must be sorted by
- cumulated cost of active tenders (can be determined by
_source.value.amount
) DESC - number of active tenders (can be determined by
_source.status
) DESC
- cumulated cost of active tenders (can be determined by
Or in other words, I need to find top-3 procuring entities that have the most active tenders and the biggest overall amount.
I’ve written the following query
this.elasticSearchService.search({
index: TENDER_INDEX_NAME,
query: {
bool: {
filter: [
{
term: {
'items.classification.cpv.keyword': cpvCode,
},
},
{
term: {
'status.keyword': 'active',
},
},
],
},
},
aggregations: {
active_tenders: {
filter: {
term: {
status: 'active',
},
},
},
active_tenders_count: {
value_count: {
field: 'status.keyword',
},
},
total_value: {
sum: {
field: 'value.amount',
},
},
},
});
Now I’m not sure what kind of result I am getting. There’s a list of tenders where CPV code matches the one I provided, but I don’t see anything related to active tenders amount or cumulated cost of all tenders. What do I need to do to get the list of procuring entities with additional properties active_tenders_amount
and cumulated_cost
? Do I need to create another index with procuring entities and a list of tenders to be able to do so?
Andrii Bryhynets is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.