es 基本语法 使用 案例
2017-03-16 12:36
337 查看
elasticsearch 语法汇总 使用 es 已有段时间 今天 有时间 就把最近使用用到的知识点 记录下来,以备后续使用 es 安装 和插件配置 等知识 这里就不在 累述 1 基本命令 使用 基于 curl 使用 命令 修改 副本信息 因为 index 一旦建成 分片个数就不能修改 只能修改 副本个数 curl -XPUT 'http://localhost:9200/test/_settings' -d '{ "index":{"number_of_replicas" : 0} }' 同样(注意 mapping 一旦创建 只能新增 不能修改) 基于 DSL 语句 查询 指定 数据 term 完全匹配 { "query":{ "term":{ "id":1 } } } match 使用 { "query":{ "match":{ "title":"bmw" } } } must 使用 必须 { "query":{ "bool":{ "must":{ "title":"baidu" } } } } must should must_not 综合使用 基本 { "query":{ "bool":{ "must":{ "title":"baidu" }, "should":{ "name":"cdd" }, "must_not":{ "age":23 } } } } must should must_not 综合使用 复杂 { "query":{ "bool":{ "must":[ { "age":2 }, { "name":"cdd" } ], "should":[],//一样用法 不在举例 "must_not":[] //一样用法 不在举例 } } } 聚合 使用 aggs max min 简单使用 { "aggs":{ "max_id":{ "max":{ "field":"id" } }, "min_id":{ "min":{ "field":"id" } } } } terms 使用 基本 { "aggs":{ "title":{ "terms":{ "field":"name", "size":10, // 显示 个数 默认10个 ,0 代表所有 最好根据情况定 } } } } terms 使用 复杂 { "aggs":{ "title":{ "terms":{ "field":"name", "size":10, // 显示 个数 默认10个 ,0 代表所有 最好根据情况定 "order":{ "score":"desc"//asc } }, "aggs":{ "score":{ "max":{ "field":"score" } } } } } } cardinality 去重 使用 统计 title 不同的总个数 { "aggs":{ "title":{ "cardinality":{ "field":"title" } } } } DSL 满足各种情况 更加复杂 的aggs 统计 如何(案例) { "size": 0, "aggs": { "daterange": { "filter": { "range": { "date": { "from": "now-2M" } } }, "aggs": { "publisher": { "terms": { "field": "publisher_na", "size": 30, "order": { "ads": "desc" } }, "aggs": { "ads": { "cardinality": { "field": "md5" } }, "date_num": { "terms": { "field": "date_day", "size": 0, "order": { "date_day": "asc" } }, "aggs": { "date_day": { "max": { "field": "date_day" } } } } } } } } } } 更为复杂 和 个别语法 请参考官网 未完 待续
相关文章推荐
- es 基本语法 使用 案例
- ASP.NET介绍及C#基本语法--案例实战
- JavaScript使用过程中的注意点和一些基本语法
- CodeSmith 使用教程(7): 基本语法-转义Asp.Net标记
- 基于JSP编译器基本语法的使用详解
- redis在PHP中的基本使用案例
- Ruby之旅(二) Ruby的基本语法以及对象的使用,方法的定义及调用,属性的定义及使用
- CodeSmith 使用教程(5): 基本语法-使用注释
- CodeSmith 使用教程(4): 基本语法-CodeTemplate 指令
- redis在PHP中的基本使用案例
- JavaScript使用过程中需要注意的地方和一些基本语法
- jquery的基本使用语法
- 使用java基本语法实现的小程序(从1000年1月1日到9999年12月31日所有的对称日)
- CodeSmith 使用教程(6): 基本语法-声明和使用属性
- 动态sql语句基本语法(字段名,表名,数据库名之类作为变量时,必须用动态SQL如ALTER TABLE中使用程序传递的参数)
- 动态sql语句基本语法(字段名,表名,数据库名之类作为变量时,必须用动态SQL如ALTER TABLE中使用程序传递的参数)
- php之路 1——Php基本语法以及变量使用
- LaTeX使用--基本语法
- css的使用和基本语法
- 基于JSP编译器基本语法的使用详解