ES技巧

2,

统计字段b的不同值的数量

{"size":0,"aggs":{"distinct_colors":{"cardinality":{"field":"b"}}}}

统计字段Local_ip的不同值

{"size":0,"aggs":{"langs":{"terms":{"field":"Local_ip","size":50000000}}}}

3,

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html

GET /products5/_search

{"query":{"match":{"name":"led tv"}},"aggs":{"resellers":{"nested":{"path":"resellers"},"aggs":{"langs":{"terms":{"field":"resellers.price","size":50000000}}}}}}

GET /products5/_search

{"query":{"bool":{"must":[],"must_not":[],"should":[],"filter":[{"nested":{"path":"resellers","query":{"bool":{"must":[{"term":{"resellers.price":44}}],"must_not":[],"should":[],"filter":[]}}}}]}},"from":0,"size":10,"sort":[]}

4,

PUT /products5/_doc/13

{"name":"LED TV","resellers":[{"price":101},{"price":110},{"price":130}],"date":"2015/02/01 05:02:00"}

GET /products5/_search

{"query":{"match":{"name":"led tv"}},"aggs":{"sales_per_month":{"date_histogram":{"field":"date","fixed_interval":"60m"},"aggs":{"resellers":{"nested":{"path":"resellers"},"aggs":{"sales":{"terms":{"field":"resellers.price","size":50000000}}}}}}}}

ES 分页

https://www.elastic.co/guide/cn/elasticsearch/guide/current/pagination.html

https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-request-from-size.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html

猜你喜欢

转载自www.cnblogs.com/WCFGROUP/p/11773679.html
今日推荐