1. 程式人生 > 實用技巧 >ElasticSearch 中 nested 型別聚合查詢語句

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 } } } } } }