ES技巧

Posted wcfgroup

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于ES技巧的主要内容,如果未能解决你的问题,请参考以下文章

es6使用技巧

译来看看这些有用的ECMAScript 2015(ES6)小技巧

六个漂亮的 ES6 技巧

LeetCode经典题分类(数学 - 数组 - 字符串)精选 - JavaScript - ES6 - 技巧总结

ES6小技巧

ES6高级技巧