inveniosoftware / invenio-records-rest

Invenio records REST API module.
https://invenio-records-rest.readthedocs.io
MIT License
4 stars 63 forks source link

support for composite aggregation #283

Closed jacgeo111 closed 4 years ago

jacgeo111 commented 4 years ago

Elasticsearch supports the below composite aggregation. But when add the below aggregation in invenio, it does not working.

GET index/_search
{
    "aggs" : {
        "my_buckets": {
            "composite" : {
                "sources" : [
                    { "field_1": { "terms" : { "field": "field_1.keyword" } } },
                    { "field_2": { "terms" : { "field": "field_2".keyword } } }
                ]
            }
        }
     }
}

The invenio configuration was specified below.

app.config['RECORDS_REST_FACETS'] = {
    index_name: {
        "aggs" : {
            "my_buckets": {
                "composite" : {
                    "sources" : [
                        { "field_1": { "terms" : { "field": "field_1.keyword" } } },
                        { "field_2": { "terms" : { "field": "field_2".keyword } } }
                    ]
                }
            }
        }
    }
}

Is Invenio supports all the Elasticsearch aggregation methods?

lnielsen commented 4 years ago

What is the value of index_name and does it match the records rest index name?

Aggregations are passed directly to ES without any modifications.

To debug the query going to Elasticsearch, you can put a breakpoint here. The search variable is an Elasticsearch DSL object, and to see the ES query simply do:

print(search.to_dict())

See details

rerowep commented 3 years ago

I have a simular problem and I got following error from elasticsearch_dsl/aggs.py ValueError: A() can only accept dict with an aggregation ({"terms": {...}}). Instead it got ... I think also if you like to see the query you have to change following file: https://github.com/inveniosoftware/invenio-records-rest/blob/master/invenio_records_rest/facets.py#L167 as mentioned above.