How to group results in elasticsearch?

前端 未结 4 1320
慢半拍i
慢半拍i 2020-12-29 10:00

I am storing Book Titles in elasticsearch and they all belong to many shops. Like this:

{
    \"books\": [
        {
            \"id\": 1,
            \"tit         


        
4条回答
  •  抹茶落季
    2020-12-29 10:50

    You can implement above desired result using Aggregation in aggregation with top_hits aggs. ex.

    aggs: {
            "set": {
                "terms": {
                    field: "id"
                },
                "aggs": {
                    "color": {
                        "terms": {
                            field: "color"
                        },
                        "aggs": {
                            "products": {
                                "top_hits": {
                                    _source:{
                                        "include":["size"]
                                    }
                                }
                            }
                        }
                    },
                    "product": {
                        "top_hits": {
                            _source:{
                                "include":["productDetails"]
                            },
                            size: 1
                        }
                    }
                }
            }
        }
    

提交回复
热议问题