Код: Выделить всё
Opensearch 2.13
Я изучаю возможность создания фасетов из моего индекса в Opensearch с использованием агрегирования сегментов и API поиска. . Я пытаюсь найти способ создания агрегирования сегментов для вложенного поля, удовлетворяющего определенному условию.
Мой индекс содержит сопоставление полей «свойств», которое является вложенным, поскольку каждый документ может содержать одно или несколько свойств, которые необходимо запросить независимо. Существуют и другие поля, такие как «type» или «createdBy», которые были созданы как сопоставления объектов, поскольку в каждом документе будет ровно по одному из каждого поля. Сопоставление показано ниже.
Код: Выделить всё
"idx_container_view_list": {
"mappings": {
"properties": {
"ancestorPath": {
"type": "keyword"
},
"color": {
"type": "keyword"
},
"coverFile": {
"type": "keyword"
},
"createdAt": {
"type": "date"
},
"createdBy": {
"properties": {
"email": {
"type": "keyword"
},
"firstname": {
"type": "keyword"
},
"lastname": {
"type": "keyword"
},
"username": {
"type": "keyword"
},
"uuid": {
"type": "keyword"
}
}
},
"deletedAt": {
"type": "date"
},
"deletedBy": ...,
"label": {
"type": "keyword"
},
"parent": {
"type": "keyword"
},
"properties": {
"type": "nested",
"properties": {
"propertyName": {
"type": "keyword"
},
"propertyUuid": {
"type": "keyword"
},
"propertyValue": {
"type": "keyword"
},
"schemaPropertyUuid": {
"type": "keyword"
},
"uuid": {
"type": "keyword"
},
"valueAsLocation": {
"properties": {
"latitude": {
"type": "long"
},
"longitude": {
"type": "long"
},
"placeName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"valueAsNumber": {
"type": "float"
}
}
},
"publishedAt": {
"type": "date"
},
"publishedBy": ...
},
"shared": {
"type": "boolean"
},
"type": {
"properties": {
"name": {
"type": "keyword"
},
"slug": {
"type": "keyword"
},
"uuid": {
"type": "keyword"
}
}
},
"updatedAt": {
"type": "date"
},
"updatedBy": ...,
"uuid": {
"type": "keyword"
}
}
}
}
Код: Выделить всё
"size" : 0,
"aggs": {
"different_container_property_types": {
"nested": {
"path":"properties"
},
"aggs": {
"property_uuid_bucket": {
"terms": {
"field": "properties.propertyUuid",
"size": 20
},
"aggs": {
"property_value_bucket": {
"terms": {
"field": "properties.propertyValue",
"size": 5
}
}
}
}
}
}
}
Код: Выделить всё
"size" : 0,
"query" : {
"nested": {
"path": "properties",
"query":{
"term": {
"properties.propertyUuid": "62329d5b-dbc9-4022-93e7-4690c9069a7e"
}
}
}
},
"aggs": {
"different_container_property_types": {
"nested": {
"path":"properties"
},
"aggs": {
"property_uuid_bucket": {
"terms": {
"field": "properties.propertyUuid",
"size": 20
},
"aggs": {
"property_value_bucket": {
"terms": {
"field": "properties.propertyValue",
"size": 5
}
}
}
}
}
}
}
Код: Выделить всё
"took": 46,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 352,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"different_container_property_types": {
"doc_count": 7624,
"property_uuid_bucket": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 583,
"buckets": [
{
"key": "02d39964-e894-4d8e-8fdd-32bf2a9c6eab",
"doc_count": 353,
"property_value_bucket": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 84,
"buckets": [...]
}
},
{
"key": "03df8c5e-61c1-4485-8978-dd2bb96c6790",
...
},
{
"key": "62329d5b-dbc9-4022-93e7-4690c9069a7e",
"doc_count": 352,
"property_value_bucket": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 77,
"buckets": [
{
"key": "b0cf8292-6005-4095-946d-51fc908243b8",
"doc_count": 138
},
{
"key": "3f5230ab-8614-436b-abc3-d5cad7f4b5a7",
"doc_count": 75
},
{
"key": "25135d79-a4c1-44a9-beed-b926b94a40fb",
"doc_count": 34
},
{
"key": "ab2807d8-1946-40e4-a156-cf3195438697",
"doc_count": 31
},
{
"key": "d03982e8-872b-4f02-a6b8-fa461e16389e",
"doc_count": 24
}
]
}
},
...
Есть ли способ получить агрегацию сегментов только для конкретного свойства uuid в запросе, чтобы избежать ненужной нагрузки в Opensearch?
Подробнее здесь: https://stackoverflow.com/questions/784 ... d-property