ElasticSearch 中 nested 类型聚合查询语句

建索引:
PUT es_latent_buy_brands_frequency {
"settings": { "number_of_replicas": 1 , "number_of_shards": 3 }, "mappings": { "doc": { "properties": { "user_id":{ "type": "keyword" }, "latent_buy_brand_frequency":{ "type": "nested", "properties": { "name":{ "type":"keyword" } } } } } } }
查询索引内数据: POST es_latent_buy_brands_frequency
/_search
查看mapping: GET es_latent_buy_brands_frequency
/_mapping
term查询: POST es_latent_buy_brands_frequency
/_search { "query": { "term": { "user_id": { "value": "1750119" } } } }
聚合查询: POST es_latent_buy_brands_frequency
/_search { "aggs": { "buy_goods_brand": { "nested": { "path": "latent_buy_brand_frequency" }, "aggs": { "agg_by_buy_goods_brand": { "terms": { "field": "latent_buy_brand_frequency.name", "size": 10 } } } } } }

 

posted @ 2020-09-02 20:41  香山上的麻雀  阅读(4224)  评论(0)    收藏  举报