码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Elasticsearch script在reindex与script_fields script get当中的应用



    本篇博客主要介绍了Elasticsearch script在reindex与script_fields script get当中的应用,主要是通过原有的字段拼接得到想要的新字段,同时在使用reindex时,指定dest_index的"_d"的值。


    目录

    • 1、Elasticsearch script在_reindex中的应用
      • script中参数解释
      • 例子如下:
    • 2、Elasticsearch script_fields script在get当中的应用
      • 参数说明
      • 列子如下:

    1、Elasticsearch script在_reindex中的应用

    POST _reindex?wait_for_completion=false
    {
      "source": {
        "index": "source_index",
        "query": {
          "bool": {
            "must": [
              {
                "range": {
                  "snapshot_time": {
                    "gte": "2022-06-01",
                    "lte": "2022-07-01"
                  }
                }
              }
            ]
          }
        }
      },
      "dest": {
        "index": "dest_index",
        "op_type": "index"
      },
      "script": {
        "inline": """
        ctx._source.bvid_page_time=ctx._source.bvid+'_'+ctx._source.page+'_'+ctx._source.snapshot_time;
        ctx._id=ctx._source.bvid_page_time;
        ctx._source.id=0
        """,
        "lang": "painless"
      },
      "conflicts": "proceed"
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    script中参数解释

    ctx._source.bvid_page_time=ctx._source.bvid+'_'+ctx._source.page+'_'+ctx._source.snapshot_time
    表示在迁移时,在source_index中增加字段"bvid_page_time",它是由source_index中的"bvid" "page" "snapshot_time"三个字段构成的,并在dest_index中也会有“bvid_page_time”字段。
    
    ctx._id=ctx._source.bvid_page_time
    表示将dest_index中的"_id"在迁移时指定为source_index中的"bvid_page_time"构成,而不是默认
    
    ctx._source.id=0
    表示在迁移过程中将source_index中的字段"id"设置为0,即dest_index中的"id"变为0,而source_index中的"id"不变
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    例子如下:

    注意,这里使用的语句就是上面的"POST _reindex"
    在这里插入图片描述
    图一 source_index

    在这里插入图片描述
    图二 dest_index


    2、Elasticsearch script_fields script在get当中的应用

    GET bili_comment_data_20220520/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "bvid": {
                  "value": "BV1******7Me"
                }
              }
            },
            {
              "term": {
                "id": {
                  "value": "3045078"
                }
              }
            }
          ]
        }
      },
      "size": 12,
      "script_fields": {
        "bvid_page_time": {
          "script": {
            "lang": "painless", 
            "source": "doc['bvid'].value+'_'+doc['page'].value+'_'+doc.snapshot_time.date.year+doc.snapshot_time.date.monthOfYear+doc.snapshot_time.date.dayOfMonth+doc.snapshot_time.date.hourOfDay+doc.snapshot_time.date.minuteOfHour+doc.snapshot_time.date.secondOfMinute"
          }
        }
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    参数说明

    表示查询是构建新的字段"bvid_page_time"返回,且仅返回构建的字段;

    列子如下:

    在这里插入图片描述

    在这里插入图片描述

  • 相关阅读:
    Camtasia2024免费版mac电脑录屏软件
    2022-08-23 第二小组 张明旭 前端学习记录
    sql面试
    libevent学习——event_base
    解决Oracle SQL语句性能问题——SQL语句改写(in、not in、exists及not exists)
    性能测试常见的测试指标
    捕捉数组越界访问问题
    (c语言进阶)指针的进阶
    MMPose 1.0:迈向更优雅、更强大的姿态估计研发和应用框架
    外星人笔记本Alienware Area-51m原装出厂Windows10系统
  • 原文地址:https://blog.csdn.net/qq_43224174/article/details/126789578
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号