ES 常用

1. ES 增加字段 设置默认值
```
        PUT hwyy_qq_friends/_mapping
        {
              "properties": {
                "last_talk_time":{
                    "type": "long"
                }
          }
        }
            POST hwyy_qq_friends/_update_by_query
            {
              "script": {
                "lang": "painless",
                "inline": "if (ctx._source.last_talk_time== null) {ctx._source.last_talk_time= '0'}"
              }
            }
```
2. ES group by count
        GET /cars/transactions/_search
        {
            "size" : 0,
            "aggs" : {
                "distinct_colors" : {
                    "cardinality" : {
                      "field" : "color"
                    }
                }
            }
        }
        
2.1. collapse(折叠)介绍
    - Field Collapsing(字段折叠)不能与scroll、rescore以及search after 结合使用。

    -     使用collapse 的字段如果是 string类型,则es 中对应 keyword。(The field used for collapsing must be a single valued keyword or numeric field with doc_values activated)
    -     查看collapse 结果
                (1)GET user/_search
                {
                    "query": {
                        "match": {
                            "address": "Place"
                        }
                    },
                    "collapse" : {
                        "field" : "age" 
                    },
                    "sort": ["age"], 
                    "from": 10
                }

                (2)Expand collapse results(对于每个折叠的结果,可以通过inner_hits展开结果)
                   // 单个inner_hits
                    GET user/_search
                    {
                        "query": {
                            "match": {
                                "address": "Place"
                            }
                        },
                        "collapse" : {
                            "field" : "age", 
                            "inner_hits": {
                                "name": "test", 
                                "size": 5, 
                                "sort": [{ "age": "asc" }] 
                            },
                            "max_concurrent_group_searches": 4 
                        },
                        "sort": ["age"]
                    }

                    // 多个inner_hits
                    GET user/_search
                    {
                        "query": {
                            "match": {
                                "address": "Place"
                            }
                        },
                        "collapse" : {
                            "field" : "age", 
                            "inner_hits":[ {
                                "name": "age", 
                                "size": 2, 
                                "sort": [{ "age": "asc" }] 
                            },
                            {
                            "name":"account_number",
                            "size": 2, 
                            "sort": [{ "account_number": "asc" }] 
                            }],
                            "max_concurrent_group_searches": 4
                        },
                        "sort": ["age"]
                    }
                // max_concurrent_group_searches:允许每组检索inner_hits的并发请求数 (默认按照线程池的大小或者数据节点数)

3、查看collapse 结果
3. ES 分页最大页数
        PUT /hwyy_wechat_qun_member_list/_settings
        {
            "index": {
                "max_result_window": 999999999
            }
        }
4. 字段设计
        “content” : {
            “type” : “text”,
                “fields” : {
                    “keyword” : {
                    “type” : “keyword”,
                    “ignore_above” : 256
                }
            }
        }
5. 查询不为空字符串的字段
        POST /hwyy_test_archives_list/_search
        {
          "track_total_hits": true, 
          "query": {
            "bool": {
              "must_not": [
                {
                  "match": {
                    "qq.keyword": ""
                  }
                }
              ]
            }
          }
        }
6. 复制数据
        POST _reindex
        {
          "source": {
            "index": "hwyy_test_fence_site_code"
          },
          "dest": {
            "index": "hwyy_live_fence_site_code",
            "op_type": "create"
          }
        }
7. 指定字段更新
        POST hwyy_live_person/_update/k7ksv3QBCeP_Wxhg7HNw
        {
           "doc" : {
                "person_id_no_img" : ""
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值