多字段聚合

curl -XPOST localhost:9200/photo -d ‘{

"photo": {

"properties": {

"id": {

"type": "String"

},

"title": {

"type": "String"

},

"category":{

"type": "String"

},

"uploader_name": {

"type": "String"

},

"uploader_id": {

"type": "String"

},

"keyword": {

"properties":{

"categoryId":{

"type": "String"

},

"content":{

"type": "String"

}

}

}

}

}

}‘

curl -XPOST localhost:9200/photo/photo/1 -d ‘{

"id":"1",

"title":"北京天坛风景",

"uploader_name":"felayman",

"uploader_id":"1",

"keyword":[

{

"categoryId":"1",

"content":"北京"

},

{

"categoryId":"2",

"content":"天坛"

},

{

"categoryId":"3",

"content":"秋天"

},

{

"categoryId":"4",

"content":"旅游"

}

]

}‘

curl -XPOST localhost:9200/photo/photo/2 -d ‘{

"id":"2",

"title":"河南",

"uploader_name":"felayman",

"uploader_id":"1",

"keyword":[

{

"categoryId":"1",

"content":"北京"

},

{

"categoryId":"4",

"content":"旅游"

}

]

}‘

curl -XGET ‘localhost:9200/photo/photo/_search?pretty‘ -d ‘{

"aggregations": {

"agg": {

"terms": {

"field": "keyword.categoryId"

}

}

}

}‘

curl -XPOST ‘localhost:9200/photo/photo/2/_update‘ -d ‘{

"doc": {"keyword" : [{

"categoryId":"2",

"content":"北京"

},

{

"categoryId":"3",

"content":"旅游"

}]}

}‘;

时间: 2024-08-29 09:40:55

多字段聚合的相关文章

TP5中多字段聚合查询,多字段运算总和(其他运算)

项目需求:获取当月每天(当天多条数据)数据汇总,需要运用到聚合查询,但是都多个字段进行分别展示. 代码如下: DB::('table_name')->where(['date' => '2020-03-24']) //这里写条件即可,比如当天->field("id,date,sum(memberactive) as 'memberactive',sum(memberadd) as 'memberadd'") //当运算完一个数据之后 as 起一个别名 用于展示->

ES之五:ElasticSearch聚合

1.单值聚合 Sum求和,dsl参考如下: { "size": 0, "aggs": { "return_balance": { "sum": { "field": "balance" } } } } 返回balance之和,其中size=0 表示不需要返回参与查询的文档. Min求最小值 { "size": 0, "aggs": { "

Elasticsearch聚合 之 Terms

本篇着重讲解的terms聚合,它是按照某个字段中的值来分类: 比如性别有男.女,就会创建两个桶,分别存放男女的信息.默认会搜集doc_count的信息,即记录有多少男生,有多少女生,然后返回给客户端,这样就完成了一个terms得统计. Terms聚合 { "aggs" : { "genders" : { "terms" : { "field" : "gender" } } } } 得到的结果如下: { ..

[elk]Mutate filter plugin增删改查字段

Mutate filter plugin参考: https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html 在线匹配: http://grokdebug.herokuapp.com/ grok github正则: https://github.com/kkos/oniguruma/blob/master/doc/RE logstash grok目录: /usr/local/logstash/vendor

MapReduce应用

1.MapReduce实现矩阵相乘 一. 准备数据 #!/bin/bash if [ $# -ne 3 ] then   echo "there must be 3 arguments to generate the two matries file!"   exit 1 fi cat /dev/null > M_$1_$2 cat /dev/null > N_$2_$3 for i in `seq 1 $1` do for j in `seq 1 $2` do s=$((

mysql-sql高级应用

sql语言进阶 典型操作 order by - select * from play_list order by createtime; - select * from play_list order by bookedcount desc,createtime asc; order by 语句用于根据指定的列对结果集进行排序 order by 语句默认按照升序对记录排序,使用desc则降序排序 order by 也可以多个字段排序,而desc只作用于一个字段: distinct select

hive-数据倾斜解决详解

今天被问到hive的数据倾斜,觉得自己对这块理解比较欠缺,某度了一下进行深入学习: hive在跑数据时经常会出现数据倾斜的情况,使的作业经常reduce完成在99%后一直卡住,最后的1%花了几个小时都没跑完,这种情况就很可能是数据倾斜的原因,解决方法要根据具体情况来选择具体的方案 1.join的key值发生倾斜,key值包含很多空值或是异常值 这种情况可以对异常值赋一个随机值来分散key 如: selectuserid , name fromuser_info a join ( select  

Elasticsearch之Nested Aggregation

(这是一个小系列:请戳:Elasticsearch之Nested(嵌套)系列,查看其他nested相关文章) In the same way as we need to use the special nested query to gain access to nested objects at search time, the dedicated nested aggregation allows us to aggregate fields in nested objects: 与在检索时

【Oracle】常用语句集合

1 oracle常用经典SQL查询 2 常用SQL查询: 3 4 1.查看表空间的名称及大小 5 6 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size 7 from dba_tablespaces t, dba_data_files d 8 where t.tablespace_name = d.tablespace_name 9 group by t.tablespace_name; 10 11 2.查看表空间物